Skip to content

Instantly share code, notes, and snippets.

@av
Created August 29, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av/ae7a73948f535a092464b4ab4ee8678e to your computer and use it in GitHub Desktop.
Save av/ae7a73948f535a092464b4ab4ee8678e to your computer and use it in GitHub Desktop.
Example of running LISP in Dart
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