I've written something that redefines T to NIL, which surprises me
because I thought that T was protected from redefinition like that, and
I have not found a command in the code that looks like it is redefining T.

Could you check it out and see if its something in the code, or a bug in
the language?

I'll copy the code here. The examples at the bottom of each function
definition are examples of how to use the function. The comment above
the function tells what it accepts, the comment beside the function name
tells what it returns:

# -> cnt
(de mtx (Size) # -> Mtx
   # Make a seed matrix, of SizexSize
   (cons (need Size T)
      (make
         (do (dec Size)
            (link (need Size)) ) ) ) )
# (mtx 4)

# -> Mtx
(de balls (Mtx)   # -> a-list ((y x) ..)
   # Gimme the coordinates of all the balls that can move
   (let (Row 1 Col (length Mtx))
      (make
         (until (= Col 1)
            (if (car (nth Mtx Row Col))
               (t
                  (link (list Row Col))
                  (inc 'Row))
               (dec 'Col) ) ) ) ) )
# (balls (mtx 4))

# -> Mtx, (y x)
(de target (Mtx Ball)   # -> pair (y x)
   # Tell me where I can move the ball.
   (let Col (cadr Ball)
      (for Row (range (car Ball) (length Mtx))
         (NIL (car (nth Mtx Row Col))
            (list Row
               (index NIL (car (nth Mtx Row))) ) ) ) ) )
# (target (mtx 4) (car (balls (mtx 4))))

# -> Mtx, (y x), (y x)
(de fall (Mtx Ball Targ)   # -> Mtx
   # Inside Mtx, move the Ball to Targ-et
   (let Ma (mapcar copy Mtx)
      (set (nth Ma (car Ball) (cadr Ball))
         NIL )
      (set (nth Ma (car Targ) (cadr Targ))
         T )
      Ma ) )
# (let Ba (car (balls (mtx 4))) (fall (mtx 4) Ba (target (mtx 4) Ba)))

# -> Mtx
(de actions (Mtx)    # a-list ((y x) ..)
   # All balls and where they fall!
   (mapcar
      '((Ball)
         (list
            Ball
            (target Mtx Ball) ) )
      (balls Mtx) ) )
# (actions (mtx 4))

# -> Mtx
(de animate (Mtx) # -> a matrix list (Mtx ..)
   (mapcar
      '((Movement)
         (fall Mtx
            (car Movement)
            (cadr Movement)))
      (actions (Mtx)) ) )
# (animate (mtx 4))

And this is the entire pil + session:

: (load "foo.l")
-> animate
: T
-> T
: (mtx 4)
-> ((T T T T) (NIL NIL NIL NIL) (NIL NIL NIL NIL) (NIL NIL NIL NIL))
: (balls (mtx 4))
-> ((1 4))
: T
-> T
: (target (mtx 4) (car (balls (mtx 4))))
-> (2 1)
: T
-> T
: (let Ba (car (balls (mtx 4))) (fall (mtx 4) Ba (target (mtx 4) Ba)))
-> ((T T T NIL) (T NIL NIL NIL) (NIL NIL NIL NIL) (NIL NIL NIL NIL))
: T
-> T
: (actions (mtx 4))
-> (((1 4) (2 1)))
: T
-> T
: (animate (mtx 4))
!? (NIL NIL NIL NIL)
NIL -- Undefined
? T
-> NIL
?

As you can see, T is still defined as T up till running 'animate, which
then fails
because T got redefined as NIL.
Also, I'm using ubuntu 16.04 LST, running picolisp version 16.6.0, the 64
bit one.

Thanks a lot for your help. Let me know if I can help in anything.

Reply via email to