Page 1 of 1

anonymous context-objects

Posted: Fri Oct 29, 2004 8:06 pm
by BrickCaster
i experiment with NewLISP and LEGO bricks, using the LDraw library standard.
i use a newlisp BRICK class, here is an excerpt:

Code: Select all

(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:

Code: Select all

(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.

Posted: Fri Oct 29, 2004 11:00 pm
by Lutz
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

Posted: Fri Oct 29, 2004 11:10 pm
by Lutz
The you also could do:

Code: Select all

(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

Posted: Sat Oct 30, 2004 5:43 pm
by BrickCaster
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.

Posted: Sat Oct 30, 2004 6:21 pm
by Lutz
good luck!

Lutz

Posted: Tue Nov 02, 2004 2:56 am
by nigelbrown
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