i experiment with NewLISP and LEGO bricks, using the LDraw library standard.
i use a newlisp BRICK class, here is an excerpt:
(constant 'red 4)
(context 'BRICK)
(define color MAIN:red)
(define (BRICK:new ctx col x y z)
(MAIN:new BRICK ctx)
(set 'ctx (eval ctx))
(set 'ctx:color col)
ctx
)
now what i want is to define LEGO models as a list of BRICKs:
(list
(BRICK:new 'ctx1 ...)
(BRICK:new 'ctx2 ...)
(BRICK:new 'ctx3 ...)
(BRICK:new 'ctx4 ...)
...
)
the problem is i want anonymous context-objets, i don't want to name each brick in my LEGO models, some have 700+ bricks.
Sorry, there are no anonymous context objects in newLISP, but perhaps you can invent some numbering scheme i.e:
(BRICK:new (symbol (format "brick-%03d" 111)) 'blue) => brick-111
brick-111:color => blue
you could also do:
(map (fn(x) (BRICK:new (symbol (format "brick%03d" x)) 'blue)) (sequence 1 5))
=> (brick001 brick002 brick003 brick004 brick005)
For making several at once, etc.
Lutz
The you also could do:
(set 'bricks (map (fn(x) (BRICK:new (symbol (format "brick%03d" x)) 'blue)) (sequence 1 5)))
=> (brick001 brick002 brick003 brick004 brick005)
(dolist (b bricks)
(set 'b:color 'black))
brick003:color => black
you can refer to the bricks by variable, etc.
Lutx
thanks for your help Lutz.
unfortunately, the more i experiment with NewLISP the more i discover how much i am biased towards the everything-is-a-first-class-value approach.
so i will probably convert my code to some Scheme or Scheme derivative.
that makes sense because animating LEGO scenes also requires some paralellism that can only be implemented using true continuations.
however, be sure i was really pleased to discover NewLISP and how well you maintain and support it.
good luck!
Lutz
Regarding anon contexts perhaps a function that will return a random symbol name that is unique within a given (or current) context could be useful viz
(anon) -> gwei842y321rui1dygk1
(anon 'CTXZ) -> gwei842y321rui1dygk1
I've used the numbered symbol generation myself but sometimes
anything will do?
I'm sure a little function could be written for it but why keep inventing it - perhaps a topic for a 5c-tip?
Nigel