-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CPP LISP] Need a helping hand implementing double #684
Comments
Next attempt, long source text:
|
That looks like a reasonable approach. You could always pass an operation argument and then share the same multiple argument code among different numeric ops. |
@emanuel4you Oh, I should note that I'm not the author of the C++ implementation. That would be @sdt all the way back in 2015. |
:) |
Hello! It would seem like the common pattern here is you have a sequence of values that might be integers, or doubles, or something else. Would it help to make some sort of utility function that walks over that sequence and checks what you have, and then return a normalised sequence? If they're all integers, then you want to operate on them as integers - you can just return the original sequence. If there's a mix of integers and doubles, then you want to operate on them as doubles. Create a new sequence by copying the doubles, and converting the integers to doubles. If there's an item that's neither an integer nor a double, throw an error. Then in code like builtin_add, call your utility function to get the normalised sequence. You know that all the values of that sequence will be the same type, so you can just check the first one to decide whether to take the integer path or the double path. |
Nice work there @emanuel4you 👍🏻 I'm not going to be able to help you with the rest I'm afraid. Regarding your |
So, I've posted everything here. Update to mal cpp: @sdt I really enjoyed the project, I see the inclusion of "while" and "repeat" as superfluous at this point, LG Emanuel |
@emanuel4you that test file indicates that recursive non-TCO code will segfault the C++ implementation. But the C++ implementation does support TCO, so you should be able to implement repeat and while forms. Something like this: For example, here is a tail-recursive Clojure style
Anyways, sounds like you've got what you needed. I'm going to close the issue now. |
Hi,
I think the LISP interpreter examples are great!
I tried to incorporate double into the cpp example.
I managed it, but I don't like it. :-(
Your code is so beautifully written,
maybe you could take a quick look at my code
and give me a few tips.
Thanks in advance
Best regards
Emanuel ;-)
This also doesn't work anymore if I want to do something like this later:
(+ 1 2 3.14 4 5)
cpp.patch.txt
The text was updated successfully, but these errors were encountered: