Charles Childers


blog | parable | retro | ios apps | fountain pens


Lexical Scope in Parable

I need to define a standard approach to lexical scoping in Parable sources. I have implementations for several things, which I'll show off briefly here.

Option 1

This takes a list of functions that should be hidden. It has a nice side effect of being able to create the headers for these up front, so variables can be used immediately:

[ 'Source' 'Dest' ] {
    [ "pp-n"  !Dest !Source ... ] 'foo' define
}

When } is executed, only the 'foo' is left visible.

Option 2

Like the first option, this takes a list, but the list is the headers to keep. Unlike the first, it does not create the headers up front:

[ 'foo' ] {
    [ 'Source' 'Dest' ] variables
    [ "pp-n"  !Dest !Source ... ] 'foo' define
}

Option 3

I use this syntax in Retro:

{
    [ 'Source' 'Dest' ] variables
---reveal---
    [ "pp-n"  !Dest !Source ... ] 'foo' define
}

Anything before the ---reveal--- is hidden.

Option 4

A variation on Option 2, this puts the list of headers to keep before the }:

{
    [ 'Source' 'Dest' ] variables
    [ "pp-n"  !Dest !Source ... ] 'foo' define
    
    [ 'foo' ]
}

Option 5

A hybrid of Options 1 & 2:

[ 'Source' 'Dest' ] {
    [ "pp-n"  !Dest !Source ... ] 'foo' define
    
    [ 'foo' ]
}

This one allows creation of variables up front and also hides any other non-specified headers.

Option 6

Use a keyword to mark functions as private, } will hide them:

{
    'Source' variable private
    'Dest' variable private
    
    [ "pp-n"  !Dest !Source ... ] 'foo' define
}

Option 7

Somewhat inspired by the Retro style syntax, but more flexible:

{
  private:
    [ 'Source' 'Dest' ] variables
  public:
    [ "pp-n"  !Dest !Source ... ] 'foo' define
}

This could allow for multiple public/private sections within a scoped area.