1
0
mirror of https://github.com/PDP-10/its.git synced 2026-01-27 20:47:38 +00:00
Files
PDP-10.its/src/teach/lesson.setq
2018-10-28 16:47:17 -07:00

49 lines
2.0 KiB
Plaintext
Executable File

.comment -*- Mode:TEXT; -*-
.comment all about SETQ
.document SETQ - How to use the SETQ function to give variables values.
.tag SETQ
Lesson SETQ, Version 2 Modified by Victoria Pigman 9/1/82
There is a magic function "SETQ" which gives things values. Unlike QUOTE, it
takes its arguments two at a time. Like QUOTE, it doesn't evaluate its first
argument. However, it does evaluate its second argument... to see what it
does, here are a few things you can try. However you should also try to come
up with a few of your own.
FOO ; will give you an error message...try to predict what else will!
'foo
(setq foo 'foo) ; note that the first argument (the
foo ; thing being SETQ'd) is not quoted.
'foo ; This is because SETQ is a magic
(setq foo 'bar) ; function. Most other functions are
foo ; not like that.
'foo
bar
(setq bar foo)
bar
'foo
(setq foo '(foo bar stuff (now then)))
foo
bar
If you get an error message, don't panic, just keep trying.
.try
Note which ones gave you error messages-- the ones you mis-typed and the ones
where a variable didn't have any value.
SETQ is actually a rather confusion causing function which is best used in a
limited fashion. One reason SETQ causes confusion is because it has an effect
which is global, that is, effective everywhere. A SETQ can have an effect in
a piece of code quite unintentionally, perhaps a piece of code in an entirely
different file. This can, and very often does, lead to very obscure and hard to
find bugs. It also makes the program very hard to read if some atom is set to
some value in one place and that information is used in another place. In
general, it is advisable to only SETQ a variable in one place, or at least in
as few places as possible, unless you are doing something like:
(SETQ FOO (CONS 'FROB FOO))
which is not so bad since it doesn't destroy the old value, merely adds to it.
This still can cause confusion in places, though.
.next COND