I've not been doing Lisp for very long, and have a few questions about
I think that I understand (defvar) variables, they are global and
special (dynamically scoped?). Reassigning them with LET is a
stack-like effect where they go back to their original value after the
Lets say I have a simple application that draws a line 100 pixels long,
from a start point toward the mouse. If the mouse is more than 100
pixels away, the line moves toward the mouse. So when you move the
mouse the line mostly follows it.
For arguments sake, lets say I want to do this with 2 functions, UPDATE
and DRAW, which recalculates the line properties & draws it,
respectively. I will need some data that is shared between these two
functions to store the line points, lets say p1 and p2.
In a simple C app, I would probably just make these global variables.
I can do this with Lisp and DEFVAR, but the variables don't really need
to be special.
In C++ I might make a class, and pass that to the functions. I can do
this with CLOS, and long term it might be a good idea, but is probably
I am currently, in Lisp, surrounding both functions with a let:
(let ((p1 nil) (p2 nil))
(defun update (x y) ...)
(defun draw ()...))
The functions are simple and clean, the data is somewhat encapsulated,
though if I need to share the data widely later it might be a problem.
So, my question is - what is the Lispy way to do what I want to do?
Are there downsides to encapsulating multiple functions with a LET?
This all doesn't feel very functional either though (I am also new to
functional programming), is this an easy problem to solve in an FP way?
11. Objective-C FAQ