Created
August 29, 2020 08:38
-
-
Save av/ae7a73948f535a092464b4ab4ee8678e to your computer and use it in GitHub Desktop.
Example of running LISP in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// LISP Scope could be populated with reuqired values | |
// to provide interop between Dart and LISP | |
final baseScope = LispScope({ | |
'*': Multiplication('*'), | |
'+': Addition('+'), | |
'offset': OffsetContainer('offset'), | |
'print': Print('print'), | |
'call': CallMethod('call'), | |
}); | |
// Expression is converted to AST | |
final expression = parse(''' | |
( | |
(define a (offset 10 10)) | |
(define b (offset 20 20)) | |
(define c b) | |
(define d c) | |
(call d 'scale' 2) | |
(print (+ a b)) | |
) | |
'''); | |
// Which can be evaluated with arbitrary scope | |
print(expression.eval(baseScope)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment