0

チキンスキーム 4.8.0.5

皆さん、こんにちは。

トップレベルの定義を含むテキスト ファイルがあるとします。

topLevelDef.txt

(define techDisplays '(
  ( AG1    fillerIgnore    AG1_fillerIgnore    t   t  nil  t  nil )
  ( AG2    drawing         AG2_drawing         t   t  nil  t   t  )
  )
)

そして私はそれをインクルードとして持ってきます

trythis.scm

(use extras format posix posix-extras regex regex-literals utils srfi-13)
(include "./mytech/mytech.tf.techDisplays") ; works when hard-coded
;include inn-file)      ; want to pass it in as an arg

(define write-out-techDisplays
  (lambda()
    (for-each
      (lambda(rule-as-list-of-symbols)
        (begin
          (set! rule-as-list-of-strings ( map symbol->string rule-as-list-of-symbols))
          (print (string-join rule-as-list-of-strings    ))
        )
      )
      techDisplays
    )
  )
)

(define (main args)
  (set! inn-file ( car args))
  (set! out-file (cadr args))
  (with-output-to-file out-file write-out-techDisplays)
0
)

では、どうすればこれを達成できますか?インクルードの評価を何らかの形で遅らせることによってですか?または inn-file の内容を読み込んで文字列を評価しますか? または、他の何か?

ティア、

まだまだ勉強中のスティーブ

4

1 に答える 1

1

必要なリストを引数として外側のラムダに渡すだけです。あなたのフォーマットは誤解を招く可能性があります。コードをきれいに印刷してみてください。

(define write-out-techdisplays
  (lambda (techdisps)
    (for-each
      (lambda (rule)
        (begin
          (set! rule-string (map symbol->string rule))
          (print (string-join rule-string)))) ;inner-lambda closes here
      techdisps)))

(define alldisps 
  (call-with-input-file "./mytech/mytech.tf.techDisplays" 
                        read)))

;since the last arg is thunk the way to invoke it is to wrap
;our call to write-out-techdisplays with a lambda to set the correct list
(with-output-to-file out-file 
                     (lambda () 
                       (write-output-techdisplays alldisps)))

最後に、コードを再設計して、副作用 (これらのセット!) なしで動作するようにすることができます。for-each はマップである可能性があります。

于 2014-12-16T23:17:48.307 に答える