orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.93k stars 396 forks source link

The 'do' function in prelude.lspy is not correct #50

Closed hitmoon closed 10 years ago

hitmoon commented 10 years ago

First, you done a great job! I think the 'do' function should be like this: ; Perform Several things in sequence (fun {do & l} { if (== l {}) {{}} {(last (map ghost l))} })

orangeduck commented 10 years ago

Hey, can you explain this? I don't think I understand the change.

hitmoon commented 10 years ago

The do function i think, is to eval each sentence in sequence and return the result of last one. This behavior is like what is means in Scheme.

orangeduck commented 10 years ago

That sounds correct. I don't think the ghost is required because the arguments to do actually come in evaluated. So the function doesn't do any evaluation itself. It just needs to return the last argument passed.

hitmoon commented 10 years ago

You can use the "max" or "min" function to test function “do”,your version give wrong output.

orangeduck commented 10 years ago

Sorry I'm still not sure I understand. Can you post a specific example? Here is do for me.

lispy> do (min 1 2 4 3) (max 10 23 33 7)
33
lispy> do (+ 10 20) (* 10 20)
200
lispy> do (print "Hello") (1)
"Hello"
1
hitmoon commented 10 years ago

sorry, from example you give , your “do” function is correct. Maybe there is a subtle difference between our code. Check my code here: github.com/hitmoon/Qlisp

orangeduck commented 10 years ago

Okay. In that case I'll close this issue. But thanks for the report and I'm glad you enjoyed the book!