Un-defun Function


#1

Hello all,
I am new to arduino (and by extension ulisp) and have been playing with a starter kit with an arduino uno I got for my birthday. Is there a function to un-defun a function, or unset it? I run out of space a lot while playing with the device, so I have been doing this to unset functions:

(defun s ()())

It doesn’t look like I get all of the memory I had before defining the function originally (I think it is still taking up memory).

Is there a good function to clear previously defined functions so I don’t have to keep unplugging the arduino?
Thank you for your help!


#2

Not entirely sure, but I think you could try to use (setq s nil), I don’t think that will completely wipe it away either as the symbol will still exist, but that should be less memory than what you were currently doing.


#3

I guess this leads me to another related question: what takes up memory? Is it individual characters that get typed into ulisp?


#4

It frees most of it, but not quite all. Try (makunbound 's).

No. To use the terminology of Lisp, the characters are fed into the reader. The reader constructs objects in memory - symbols, integers, cons cells and so on. Lists are made using linked cons cells, and the evaluator works with those lists.


#5

Thanks! I’ll try out makunbound. I didn’t realize this was the function!

Also, thank you for the great explanation about memory. With common lisp, I’ve never had to worry about memory before, so it was never on my mind!


#6

uLisp doesn’t have distinct namespaces for functions and variables, so makunbound works for both - in Common Lisp you’d need to use fmakunbound, and I’m pretty sure if uLisp ever does sprout a second namespace, that function would come along for the ride. :p

As for Common Lisp and memory, that’s understandable. uLisp runs on some extremely constrained platforms - the Arduino Uno being a prime example. :p


#7

I just wanted to also point out how great the (globals) function is to have in ulisp. I was thinking “Wouldn’t it be great to have a function that shows me what is taking up my precious memory?” That is a great feature to have in the language.


#8

And (pprintall) is useful to pretty-print everything in your workspace.


#9

I have been using Common Lisp since early 2000s, and I have been reading the forum with great interest, hoping to use ulisp in the near future.

I like the functionality of (globals) and (pprintall). Any pointer on how to implement them in Common Lisp?


#10

It’s not quite so easy in Common Lisp; see:

You could then call pprint on each of them.


#11

Thanks.

I thought one way to make it easier is to be disciplined, and only work inside packages.

Then, do something like,

(let ((syms nil))
 (do-symbols (sym (find-package "MY-PACKAGE"))
    (push sym syms))
syms)