[PLA] Comment to PLA00004: simplification of expression blocks

Clifford Wolf clifford at clifford.at
Sun Nov 25 14:10:54 CET 2007


Hi ak,

On Sun, Nov 25, 2007 at 01:17:46PM +0100, Andreas Krennmair wrote:
> So, if I understand this correctly, why would the ( ) be needed at all?
> An expression such as 
> 
> 	( m * c * c )
> 
> Could instead be expressed as 
> 
> 	{ m * c * c }()

Sure, but there is a difference between

	( %a + %b )

and

	{ %a + %b }()

> Regarding variable scopes in this example: to have the { }() construct
> behave like the () construct, we need to take care of variables that are
> outside the scope of the { } block. The (IMHO) obvious strategy for
> variable name resolution is to resolve with all declared variables at
> the time of creation of the { } block, i.e.
> 
> 	a := 3;
> 	foo := { a * a }
> 
> would be ok, while
> 
> 	foo := { a * a };
> 	a := 3;
> 	b := foo()
> 
> would yield an error at line 1, as variable a is undeclared at that
> time. I don't see anything in PLA00004 that contradicts this strategy.

no, as in SPL I would make namespace resolution at runtime. This is
important because otherwise some things (e.g. strange recursion pattern)
wouldnt be possible without having
function prototypes.

So it is just improtant that a is declared in the parent context of foo
when foo is called, not when it is declared. That's at least what I had in
mind when writing the document..

> In addition, you get nested functions (with Pascal-style behaviour wrt
> variable scoping) for free:
> 
> 	e := {
> 		f := { %x + %y };
> 		f(y: 3);
> 	};
> 	e(x: 4) // evaluates to 7

ah ok - now I see what you mean.
I had something different in mind:

The %foobar thing could just be a com¼pilershortcut for %.args.foobar, %
beeing the current execution context and %.args a hash with all arguments.

so it would be possible to write

	e := {
		eargs := %.args;
		f := { eargs.x + %y };
		f(y: 3);
	};
	e(x: 4) // evaluates to 7

or the SPL like solution would be

	e := {
		f := { %x + %y };
		f(y: 3, ### %.args);
	};
	e(x: 4) // evaluates to 7

(### beeing an operator to include key-value pairs from a hash in an
argument list, in SPL this oprator is %, but this would obviously need to
be a different operator in the proposed syntax).

I think we would need some standard library function for checking arguments
because there are no prototypes in this language. Having them all in a
single hash which can be e.g. passed makes things much easier.

However, it would be possible to impement %foo using a different lookup
method as %.args.foo so %foo also looks in parent function contexts..

> Just my 2.97 US-??. ;-)

yours,
 - clifford

-- 
Most of the VAX instructions are in microcode, but HALT and NO-OP are in
hardware for efficiency.


More information about the PLA mailing list