Live data from Hacker News

Show HN: Minimal Lisp in ~70 lines of Haskell

gist.github.com

21–24 of 24 posts

Re: Show HN: Minimal Lisp in ~70 lines of Haskell

#21
post #9

The content of Fun is actually the type: Context -> Value -> (Context, Value). If you flip the arguments, you get: Value -> Context -> (Context, Value). The (Context -> (Context, Value)) is actually the State type: State s a = s -> (s, a) I modified your code to use this type. During the process, I encountered some peculiar things (and factored out some things), see comments in code. https://gist.github.com/950445 Fu…

The eval throwing away context does not make any sense in retrospect. I think I made it that way because of some ghetto-scoping ideas.

You broke car and cdr somehow (these don't evaluate their arguments anymore), but I have no idea how you did this.

This was mostly a training exercise, this is why there is no significant use of monads in there: I simply haven't learned enough about them to feel comfortable using them.

Re: Show HN: Minimal Lisp in ~70 lines of Haskell

#22
post #9

The content of Fun is actually the type: Context -> Value -> (Context, Value). If you flip the arguments, you get: Value -> Context -> (Context, Value). The (Context -> (Context, Value)) is actually the State type: State s a = s -> (s, a) I modified your code to use this type. During the process, I encountered some peculiar things (and factored out some things), see comments in code. https://gist.github.com/950445 Fu…

The eval throwing away context does not make any sense in retrospect. I think I made it that way because of some ghetto-scoping ideas. You broke car and cdr somehow (these don't evaluate their arguments anymore), but I have no idea how you did this. This was mostly a training exercise, this is why there is no significant use of monads in there: I simply haven't learned enough about them to feel comfortable using them…

Can you give the example that breaks car/cdr? They seem to be evaluating their args here:

    fst $ repl "(car (cons 1 (quote ())))"
    Number 1

Re: Show HN: Minimal Lisp in ~70 lines of Haskell

#23
post #22

Earlier quoted context omitted.

The eval throwing away context does not make any sense in retrospect. I think I made it that way because of some ghetto-scoping ideas. You broke car and cdr somehow (these don't evaluate their arguments anymore), but I have no idea how you did this. This was mostly a training exercise, this is why there is no significant use of monads in there: I simply haven't learned enough about them to feel comfortable using them…

Can you give the example that breaks car/cdr? They seem to be evaluating their args here: fst $ repl "(car (cons 1 (quote ())))" Number 1

Sorry, that was my fault. I didn't make lambdas evaluate their arguments and I didn't notice this in my code. I.e. car/cdr work correctly, fun doesn't.

Re: Show HN: Minimal Lisp in ~70 lines of Haskell

#24
post #12

Cool, only 70 lines!! (plus a ton of libraries) j/k ;-) Actually, I like this - it shows how cool Haskell really is! No, wait - it shows how cool Lisp really is! No wait... I'm confused... :-)

You might also like: Lisprolog http://stud1.tuwien.ac.at/~e0225855/lisprolog/lisprolog.html

"Some online books show how to implement a simple "Prolog" engine in Lisp. They typically assume a representation of Prolog programs that is convenient from a Lisp perspective, and can't even parse a single proper Prolog term. Instead, they require you to manually translate Prolog programs to Lisp forms that are no longer valid Prolog syntax. With this approach, implementing a simple "Lisp" in Prolog is even easier ("Lisp in Prolog in zero lines"): Manually translate each Lisp function to a Prolog predicate with one additional argument to hold the original function's return value. Done. This is possible since a function is a special case of a relation, and functional programming is a restricted form of logic programming.

Here is a bit beyond that: lisprolog.pl

These 162 lines of Prolog code give you an interpreter for a simple Lisp, including a parser to let you write Lisp code in its natural form."

Post reply on HN