Mal – Make a Lisp, in 68 languages
github.com
Mal – Make a Lisp, in 68 languages
1–10 of 74 posts
Re: Mal – Make a Lisp, in 68 languages
#2Re: Mal – Make a Lisp, in 68 languages
#3The radically simple implementation of TCO really surprised me.
Re: Mal – Make a Lisp, in 68 languages
#4Re: Mal – Make a Lisp, in 68 languages
#5Re: Mal – Make a Lisp, in 68 languages
#6Why?
I had a go in Rust recently. Was a great way to learn new things about Rust and also some interpreter concepts.
Re: Mal – Make a Lisp, in 68 languages
#7Could someone explain this gem in the C version? https://github.com/kanaka/mal/blob/master/c/types.c#L170
For example, when arg_cnt is 2, mv->val.f2 receives func converted to void * (* )(void* , void* ), that is, pointer to a function that accepts two parameters of type pointer-to-void and returns pointer-to-void. [Weird spacing to effectively escape the asterisks that would otherwise be treated as italicizing markup.]
C permits conversion between pointer-to-function of one type to pointer-to-function of another type. The inverse is also defined, and the resulting pointer will compare equal to the original. However, calling a function through a pointer-to-function where the types do not match invokes undefined behavior.
[0]: https://github.com/kanaka/mal/blob/master/c/types.h#L85
Re: Mal – Make a Lisp, in 68 languages
#8Why?
Re: Mal – Make a Lisp, in 68 languages
#9Could someone explain this gem in the C version? https://github.com/kanaka/mal/blob/master/c/types.c#L170
In struct MalVal[0], the values f0 through f20, where each holds a pointer-to-functions of the corresponding arity, live in a big (multifacted?) union. Using arg_cnt, the switch assigns func to the appropriate value in mv->val using the appropriate cast. For example, when arg_cnt is 2, mv->val.f2 receives func converted to void * (* )(void* , void* ), that is, pointer to a function that accepts two parameters of type…
case 13: mv->val.f13 = (F13)func; break;
As a C programmer I got to say people in general don't use typedef for function pointer types often enough. The types are so ugly and verbose, they should be typedef'ed by default.Re: Mal – Make a Lisp, in 68 languages
#10Question: how do I go from tackling this to tackling compilers?