Closed ptdecker closed 10 years ago
I think you are almost there. So in the previous chapter you can simply check if a variable is already defined just by checking if it exists in the environment.
In this chapter you need to check if a variable is defined and that it is a builtin function. I guess my hint would be that if the variable is defined, you know you can actually get a copy of it from the enviroment and inspect it's fields manually (such as builtin
), hope that helps.
Thanks,
Dan
I will give that route a try. I was mentally resisting making a copy just to then destroy it but I need to put that aside. Thank you for the advice.
First of all, thank you for the tutorial. It is wonderful.
Second, I would appreciate a hint on how to proceed to implement the check to guard against redefining an internal function.
I continue to work through it and after completing the variables chapter had code that worked to prevent the redefinition of an internal variable. However, this approach was broken when I implemented the basic functions code and I haven't been able to figure out a better and workable approach. Below is a link to a snapshot of where I am at. I believe the approach has to be to add a check for 'builtin' in lvar as not NULL within the 'builtin_var' function at the point where I currently have the 'printf' to list the symbol being scanned (line 988).
https://github.com/ptdecker/lispy/blob/8cd829339587eeeb78cc39b47c68347fcf50c9b0/functions.c