Symbols in context qualified functions not in that context

Pondering the philosophy behind the language
Locked
itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Symbols in context qualified functions not in that context

Post by itistoday »

One area that I think newLISP could use a lot of improvement in is in dealing with contexts.

I've been thwarted multiple times in my attempts at creating useful and awesome macros for newLISP's FOOP stuff.

As just one example consider the define-subclass macro I wrote:

Code: Select all

(define-macro (define-subclass)
   (new (args 0 1) (args 0 0))
   (dolist (method (rest $args))
      (setf (method 0 0) (sym $it (args 0 0)))
      (eval (push 'define method))
   )
)
Although that lets you write really succinct and beautiful code like this:

Code: Select all

(define-subclass (Bar Foo)
   ((get x) (x 2))
   ((set x v) (setf (x 2) v) x)
   ((str x) (string x))
)
It is currently useless for several reasons:
  1. It can't be called outside of the MAIN context.
  2. But most importantly, all of the variables and parameters inside those functions are in the MAIN context, not the Bar context
As another example, in working on the Dragonfly web framework for newLISP I thought it would be great if Dragonfly provided a convenient macro for creating routes like this:

Code: Select all

(define-route (MyRoute)
	((matches?)
		... code ...
	)
	((run)
		... more code ...
	)
)
While this can be done, it's severely handicapped right now because of the previously stated reasons. It can't be called outside of the MAIN context, and any symbols in those 'matches?' and 'run' functions will be in the MAIN context (unless each is verbosely qualified), despite the current ability of creating such a macro that context-qualifies the 'matches?' and 'run' functions.

Instead, routes currently must be defined verbosely like this:

Code: Select all

(context MAIN)
(new Route 'Route.Resource)
(context Route.Resource)

(define (matches?)
	... code ...
)
(define (run)
	... more code ...
)
And that must be done for *each route*! Compare the two approaches:

Code: Select all

(context MAIN)
(new Route 'Route.Resource)
(context Route.Resource)

(define (matches?)
	... code ...
)
(define (run)
	... more code ...
)

(context MAIN)
(new Route 'Route.Static)
(context Route.Static)

(define (matches?)
	... code ...
)
(define (run)
	... more code ...
)
Versus:

Code: Select all

(define-route (Route.Resource) 
	((matches?)
		... code ...
	)
	((run)
		... more code ...
	)
)

(define-route (Route.Static)
	((matches?)
		... code ...
	)
	((run)
		... more code ...
	)
)
Why does this happen? Because newLISP can't switch contexts inside of a function call.

Thus, I'd like to be able to rewrite the 'define-subclass' fexpr like this, but I can't:

Code: Select all

(define-macro (define-subclass)
	(new (args 0 1) (args 0 0))
	(context (args 0 0))
	(dolist (method (rest $args))
		(setf (method 0 0) (sym $it (args 0 0)))
		(eval (push 'define method))
	)
	(context MAIN)
)
Any chance of this becoming possible? Or at least making 'eval' place unqualified symbols in the same context as the function? I think it would be a great boon the language if such things were possible in newLISP, the possibilities it would open would be great!
Get your Objective newLISP groove on.

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Re: Symbols in context qualified functions not in that context

Post by m35 »

I hate to say it, but the limitations surrounding context referencing are the longest running issues that have bugged me about newLISP. I first ran into them over 2 years ago, shortly after stumbling upon the language.

I really like newLISP, and definitely don't want to diminish Lutz's hard work and immeasurable generosity. I'm just bummed these limitations are still around.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Symbols in context qualified functions not in that context

Post by Lutz »

previous post here was in the wrong location and has been moved here:

http://newlispfanclub.alh.net/forum/vie ... 978#p16978
Last edited by Lutz on Tue Oct 27, 2009 6:05 pm, edited 2 times in total.

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Re: Symbols in context qualified functions not in that context

Post by itistoday »

Lutz wrote:
Really? I thought "$this" referencing the function is impossible, because of "one reference only."
..[snip]..
Wrong thread?
Get your Objective newLISP groove on.

Locked