4 ms·
Here's a minimal dialect of Lisp embedded in PHP, in 272 lines: https://github.com/igorw/yolo/blob/master/src/yolisp.php https://github.com/igorw/yolo/blob/mas
by TazeTSchnitzel 12y ago
Here's a minimal dialect of Lisp embedded in PHP, in 272 lines:
https://github.com/igorw/yolo/blob/master/src/yolisp.php https://github.com/igorw/yolo/blob/master/src/yolisp.php
It could be shorter, but as written, it can use almost all PHP's operators (as dynamically generated functions), interact with PHP classes and functions, and produce closures that PHP code can call.
Actual code sample (albeit a poor one):
https://github.com/igorw/yolo/blob/master/src/yolo.php#L19-30 https://github.com/igorw/yolo/blob/master/src/yolo.php#L19-3...
Implementation of map could be done like this (tested and it works):
y('let',
y(y('map', y('lambda',
y('func', 'data'),
y('if',
y('==', 'nil', 'data'),
'nil',
y('cons',
y('func', y('car', 'data')),
y('map', 'func', y('cdr', 'data'))
)
)
)),
/* ... */
)
- sethrin 12y agoThat's fascinating. What is performance like?
- TazeTSchnitzel 12y agoI've done absolutely no profiling on it, but I suspect it isn't exactly fantastic, particularly since any function call involves a linked-list to PHP array conversion, then array to internal PHP parameter list conversion.