lisp for groovy?

classic Classic list List threaded Threaded
16 messages Options
12
Reply | Threaded
Open this post in threaded view
|

lisp for groovy?

Jochen Theodorou
Hi,

my proposal may be a little bit odd in the result, but I really think it
could be very useful. My proposal consists of 3 Points

1) no top-level statements in lists
2) new Token "°" or something different to make a symbol out of a identifier
3) remove "," from lists or make them optional

this enables us to make list like this one:

[°select "*" °from table °where foo "=" bar]

table, foo and bar are handled as varibales
all tokens prefixed with ° are symbols, for this a new class
groovy.lang.Symbol will be created, which contains the property name, to
get the name of the symbol.

Advantages:
  * easy way to deinfe DSLs

Disadvantages:
  * we are loosing top-level statements in lists (point 3 requires 1)
  * [ is not (
  * ° is not '
  (* it is no lisp because there are no makros)
  * poeple don't like lisp like structures ;)


I think the advantages are more important
comments?

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

spullara.1684899
I like the idea, but that symbol isn't on US keyboards so I doubt we could
really use it.  Maybe use : like in ruby?



Sam



--- [hidden email]
wrote:

Hi,

>

> my proposal may be a little bit odd in the result, but
I really think it

> could be very useful. My proposal consists of 3 Points

>

> 1) no top-level statements in lists

> 2) new Token "�" or something
different to make a symbol out of a identifier

> 3) remove "," from lists
or make them optional

>

> this enables us to make list like this one:

>

> [�select "*" �from table �where foo "=" bar]


Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

Guillaume Laforge
Administrator
In reply to this post by Jochen Theodorou
Hi Jochen

Interesting idea, though the syntax seems a bit foreign :-)

On the other hand, simply allowing optional colons inside lists could
bring us what you're after in that example... as long as you're doing
that inside a closure, so that those keywords are retrieved from the
englobing closure metaclass. Let's see that more clearly in the same
example:

dsl.sql{ [ select "*" from bar where foo "=" x ] }

It almost looks like the real sql syntax, and the unknown elements
would be checked against the closure metaclass which would know how to
interpret select or from.

Just my 2 euro-cents

On 02/01/06, Jochen Theodorou <[hidden email]> wrote:

> Hi,
>
> my proposal may be a little bit odd in the result, but I really think it
> could be very useful. My proposal consists of 3 Points
>
> 1) no top-level statements in lists
> 2) new Token "°" or something different to make a symbol out of a identifier
> 3) remove "," from lists or make them optional
>
> this enables us to make list like this one:
>
> [°select "*" °from table °where foo "=" bar]
>
> table, foo and bar are handled as varibales
> all tokens prefixed with ° are symbols, for this a new class
> groovy.lang.Symbol will be created, which contains the property name, to
> get the name of the symbol.
>
> Advantages:
>   * easy way to deinfe DSLs
>
> Disadvantages:
>   * we are loosing top-level statements in lists (point 3 requires 1)
>   * [ is not (
>   * ° is not '
>   (* it is no lisp because there are no makros)
>   * poeple don't like lisp like structures ;)
>
>
> I think the advantages are more important
> comments?
>
> bye blackdrag
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

Jochen Theodorou
In reply to this post by spullara.1684899
[hidden email] schrieb:

> I like the idea, but that symbol isn't on US keyboards so I doubt we could
> really use it.  Maybe use : like in ruby?


well we have one of ^%#~, : is not ok because [foo :bar] would be a list
and [foo : bar] not. That's to problematic. # is a bit bold, but ok for
me. (I always wanted # not to be used for line comments ;))
We can also use 2 characters.. but even then I wouldn't use :: because
of maps: [foo ::bar] is a list and [foo:::bar] is a map, but is it
verbose enough to see that?

bye blackdrag

Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

mythz
I personally prefer the %,& or $ symbols.


On 1/2/06, Jochen Theodorou <[hidden email]> wrote:
[hidden email] schrieb:

> I like the idea, but that symbol isn't on US keyboards so I doubt we could
> really use it.  Maybe use : like in ruby?


well we have one of ^%#~, : is not ok because [foo :bar] would be a list
and [foo : bar] not. That's to problematic. # is a bit bold, but ok for
me. (I always wanted # not to be used for line comments ;))
We can also use 2 characters.. but even then I wouldn't use :: because
of maps: [foo ::bar] is a list and [foo:::bar] is a map, but is it
verbose enough to see that?

bye blackdrag


Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

mythz
A cleaner solution might be allowing for an 'escape mode', e.g.

def query = <sql>select: * from: $table where: field = $bar</sql>
query.where += "field2 is null"

def sql = Sql.newInstance("jdbc:<a href="mysql://localhost:3306/mydb">mysql://localhost:3306/mydb", "user", "pswd", "com.mysql.jdbc.Driver")
sql.eachRow(query) {
  println ${it.field}
}

other examples:

def essay = new java.io.File("${path}")
def wordcount = <shell>cat: ${essay.canonicalPath} | wc: -w</shell>
def gsh = new com.baulsupp.groovy.groosh.Groosh();
gsh.exec(wordcount) {
  println "${essay.name}: has ${it} words"
}

Comments?

On 1/3/06, Demis Bellot <[hidden email]> wrote:
I personally prefer the %,& or $ symbols.



On 1/2/06, Jochen Theodorou <[hidden email]> wrote:
[hidden email] schrieb:

> I like the idea, but that symbol isn't on US keyboards so I doubt we could
> really use it.  Maybe use : like in ruby?


well we have one of ^%#~, : is not ok because [foo :bar] would be a list
and [foo : bar] not. That's to problematic. # is a bit bold, but ok for
me. (I always wanted # not to be used for line comments ;))
We can also use 2 characters.. but even then I wouldn't use :: because
of maps: [foo ::bar] is a list and [foo:::bar] is a map, but is it
verbose enough to see that?

bye blackdrag



Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

tugwilson
In reply to this post by Jochen Theodorou

On 2 Jan 2006, at 20:58, Jochen Theodorou wrote:

> Hi,
>
> my proposal may be a little bit odd in the result, but I really  
> think it could be very useful. My proposal consists of 3 Points
>
> 1) no top-level statements in lists
> 2) new Token "°" or something different to make a symbol out of a  
> identifier
> 3) remove "," from lists or make them optional
>
> this enables us to make list like this one:
>
> [°select "*" °from table °where foo "=" bar]
>
> table, foo and bar are handled as varibales
> all tokens prefixed with ° are symbols, for this a new class  
> groovy.lang.Symbol will be created, which contains the property  
> name, to get the name of the symbol.
>
> Advantages:
>  * easy way to deinfe DSLs
>
> Disadvantages:
>  * we are loosing top-level statements in lists (point 3 requires 1)
>  * [ is not (
>  * ° is not '
>  (* it is no lisp because there are no makros)
>  * poeple don't like lisp like structures ;)
>
>
> I think the advantages are more important
> comments?

I think you can do this without needing to explicitly distinguish  
symbols from other names:

If your construct created a list and an instance of a metaclass then  
the list could be a list of names, values and tokens.

{<select * from table where foo = bar>}

This would create a list [new Name("select"), new Token("*"), new Name
("from"), ......] and a metaclass instance capable of resolving names  
at the point when the list is created (i.e. much like the metaclass  
for a closure).

The DSL looks at each name and can tell if it is a symbol or a  
variable name (as it knows the spelling of all the symbols it  
supports). It uses the metaclass to access properties and call methods.

Variables which refer to local on stack values are handled in exactly  
the same way as with closures.



John Wilson
The Wilson Partnership
http://www.wilson.co.uk


Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

mythz
well I was thinking

def query = <sql>select: * from: $table where: field = $bar</sql>
query.where += "field2 is null"

could be more strongly typed and essentially equivalent to:

def query = [select:new SqlSelect("*"),from:new SqlFrom("$table"), where:new SqlWhere("field = $bar")]
query.where.add("field2 is null")

so 'invalid symbols' could be a compile-time error

on a similar note:

def wordcount = <shell>cat: ${essay.canonicalPath} | wc: -w</shell>

would be equivalent to:

def wordcount = [cat:new ShellCat("${essay.canonicalPath}"),pipe:new ShellPipe(),wc:new ShellWc("-w")]

but yeah it could always be more builder friendly:

def query = sql.{
  select(*)
  from($table)
  where(field:$bar)
}
def wordcount = shell.{
  cat(essay.canonicalPath)
  pipe { wc(-w) }
}

Demis


On 1/5/06, John Wilson <[hidden email]> wrote:

On 2 Jan 2006, at 20:58, Jochen Theodorou wrote:

> Hi,
>
> my proposal may be a little bit odd in the result, but I really
> think it could be very useful. My proposal consists of 3 Points
>

> 1) no top-level statements in lists
> 2) new Token "°" or something different to make a symbol out of a
> identifier
> 3) remove "," from lists or make them optional
>
> this enables us to make list like this one:
>
> [°select "*" °from table °where foo "=" bar]
>
> table, foo and bar are handled as varibales
> all tokens prefixed with ° are symbols, for this a new class
> groovy.lang.Symbol will be created, which contains the property
> name, to get the name of the symbol.
>
> Advantages:
>  * easy way to deinfe DSLs
>
> Disadvantages:
>  * we are loosing top-level statements in lists (point 3 requires 1)
>  * [ is not (
>  * ° is not '
>  (* it is no lisp because there are no makros)
>  * poeple don't like lisp like structures ;)
>
>
> I think the advantages are more important
> comments?

I think you can do this without needing to explicitly distinguish
symbols from other names:

If your construct created a list and an instance of a metaclass then
the list could be a list of names, values and tokens.

{<select * from table where foo = bar>}

This would create a list [new Name("select"), new Token("*"), new Name
("from"), ......] and a metaclass instance capable of resolving names
at the point when the list is created (i.e. much like the metaclass
for a closure).

The DSL looks at each name and can tell if it is a symbol or a
variable name (as it knows the spelling of all the symbols it
supports). It uses the metaclass to access properties and call methods.

Variables which refer to local on stack values are handled in exactly
the same way as with closures.



John Wilson
The Wilson Partnership
http://www.wilson.co.uk



Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

mythz
actually with optional braces (not sure if it works in builders) we might be able to do:

def query = sql.{
  select "*"
    from table
  where field:$bar
     and field2:"is null"
}

for free?

On 1/5/06, Demis Bellot <[hidden email]> wrote:
well I was thinking

def query = <sql>select: * from: $table where: field = $bar</sql>
query.where += "field2 is null"

could be more strongly typed and essentially equivalent to:

def query = [select:new SqlSelect("*"),from:new SqlFrom("$table"), where:new SqlWhere("field = $bar")]
query.where.add("field2 is null")

so 'invalid symbols' could be a compile-time error

on a similar note:

def wordcount = <shell>cat: ${essay.canonicalPath} | wc: -w</shell>

would be equivalent to:

def wordcount = [cat:new ShellCat("${essay.canonicalPath}"),pipe:new ShellPipe(),wc:new ShellWc("-w")]

but yeah it could always be more builder friendly:

def query = sql.{
  select(*)
  from($table)
  where(field:$bar)
}
def wordcount = shell.{
  cat(essay.canonicalPath)
  pipe { wc(-w) }
}

Demis



On 1/5/06, John Wilson <[hidden email]> wrote:

On 2 Jan 2006, at 20:58, Jochen Theodorou wrote:

> Hi,
>
> my proposal may be a little bit odd in the result, but I really
> think it could be very useful. My proposal consists of 3 Points
>
> 1) no top-level statements in lists
> 2) new Token "°" or something different to make a symbol out of a
> identifier
> 3) remove "," from lists or make them optional
>

> this enables us to make list like this one:
>
> [°select "*" °from table °where foo "=" bar]
>
> table, foo and bar are handled as varibales
> all tokens prefixed with ° are symbols, for this a new class
> groovy.lang.Symbol will be created, which contains the property
> name, to get the name of the symbol.
>
> Advantages:
>  * easy way to deinfe DSLs
>
> Disadvantages:
>  * we are loosing top-level statements in lists (point 3 requires 1)
>  * [ is not (
>  * ° is not '
>  (* it is no lisp because there are no makros)
>  * poeple don't like lisp like structures ;)
>
>
> I think the advantages are more important
> comments?

I think you can do this without needing to explicitly distinguish
symbols from other names:

If your construct created a list and an instance of a metaclass then
the list could be a list of names, values and tokens.

{<select * from table where foo = bar>}

This would create a list [new Name("select"), new Token("*"), new Name
("from"), ......] and a metaclass instance capable of resolving names
at the point when the list is created (i.e. much like the metaclass
for a closure).

The DSL looks at each name and can tell if it is a symbol or a
variable name (as it knows the spelling of all the symbols it
supports). It uses the metaclass to access properties and call methods.

Variables which refer to local on stack values are handled in exactly
the same way as with closures.



John Wilson
The Wilson Partnership
<a href="http://www.wilson.co.uk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.wilson.co.uk




Reply | Threaded
Open this post in threaded view
|

Re: lisp for groovy?

mythz
(apologizing for the multiple posts...)
A more legal syntax being:

def table = "mytable"
def bar = "value"

def query = sql.{
  select "*"
    from table
  where [field:bar]                  // or where[field:bar,field2:"is null",etc]
     and [field2:"is null"]
}


On 1/5/06, Demis Bellot <[hidden email]> wrote:
actually with optional braces (not sure if it works in builders) we might be able to do:

def query = sql.{
  select "*"
    from table
  where field:$bar
     and field2:"is null"
}

for free?


On 1/5/06, Demis Bellot <[hidden email]> wrote:
well I was thinking

def query = <sql>select: * from: $table where: field = $bar</sql>
query.where += "field2 is null"

could be more strongly typed and essentially equivalent to:

def query = [select:new SqlSelect("*"),from:new SqlFrom("$table"), where:new SqlWhere("field = $bar")]
query.where.add("field2 is null")

so 'invalid symbols' could be a compile-time error

on a similar note:

def wordcount = <shell>cat: ${essay.canonicalPath} | wc: -w</shell>

would be equivalent to:

def wordcount = [cat:new ShellCat("${essay.canonicalPath}"),pipe:new ShellPipe(),wc:new ShellWc("-w")]

but yeah it could always be more builder friendly:

def query = sql.{
  select(*)
  from($table)
  where(field:$bar)
}
def wordcount = shell.{
  cat(essay.canonicalPath)
  pipe { wc(-w) }
}

Demis



On 1/5/06, John Wilson <[hidden email]> wrote:

On 2 Jan 2006, at 20:58, Jochen Theodorou wrote:

> Hi,
>
> my proposal may be a little bit odd in the result, but I really
> think it could be very useful. My proposal consists of 3 Points
>
> 1) no top-level statements in lists
> 2) new Token "°" or something different to make a symbol out of a
> identifier
> 3) remove "," from lists or make them optional
>

> this enables us to make list like this one:
>
> [°select "*" °from table °where foo "=" bar]
>
> table, foo and bar are handled as varibales
> all tokens prefixed with ° are symbols, for this a new class
> groovy.lang.Symbol will be created, which contains the property
> name, to get the name of the symbol.
>
> Advantages:
>  * easy way to deinfe DSLs
>
> Disadvantages:
>  * we are loosing top-level statements in lists (point 3 requires 1)
>  * [ is not (
>  * ° is not '
>  (* it is no lisp because there are no makros)
>  * poeple don't like lisp like structures ;)
>
>
> I think the advantages are more important
> comments?

I think you can do this without needing to explicitly distinguish
symbols from other names:

If your construct created a list and an instance of a metaclass then
the list could be a list of names, values and tokens.

{<select * from table where foo = bar>}

This would create a list [new Name("select"), new Token("*"), new Name
("from"), ......] and a metaclass instance capable of resolving names
at the point when the list is created (i.e. much like the metaclass
for a closure).

The DSL looks at each name and can tell if it is a symbol or a
variable name (as it knows the spelling of all the symbols it
supports). It uses the metaclass to access properties and call methods.

Variables which refer to local on stack values are handled in exactly
the same way as with closures.



John Wilson
The Wilson Partnership
<a href="http://www.wilson.co.uk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.wilson.co.uk





12