Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (use-modules (ice-9 rdelim))
- (define (parse-line line)
- (let* ((parse (string-tokenize line))
- (len (length parse))
- (monkey (string->symbol (string-trim-right (car parse) #\:))))
- (cond
- ((= 2 len) (list 'define (list monkey) (string->number (cadr parse))))
- ((= 4 len) (list 'define (list monkey) (list
- (string->symbol (caddr parse))
- (list (string->symbol (cadr parse)))
- (list (string->symbol (cadddr parse))))))
- (#t (error "Malformed input")))))
- (define (parse-proc l)
- (let ((line (read-line)))
- (if (eof-object? line)
- l
- (parse-proc (append l (list (parse-line line)))))))
- (define code (with-input-from-file "input.txt" (lambda () (parse-proc '()))))
- (primitive-eval `(let () ,@code (root)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement