Special Syntax for calling .NET

Jan 5, 2010 at 2:29 AM

Is there any way to define a special reader syntax for calling .net?

Sort of like this

http://jscheme.sourceforge.net/jscheme/doc/javadot.html

Thanks!

Coordinator
Jan 5, 2010 at 8:11 AM

Hi

There is currently no support for adding/modifying reader syntax.

But I have been pondering some ideas to have extensible reader syntax, just not sure about it yet, or if it would even be beneficial.

EG for regex one could use #re(a|b|c) perhaps, but one could just use a simple string too. I honestly do not see much benefit.

To get back to what you are asking. I have developed a 'shorthand' macro library for calling .NET. See http://xacc.wordpress.com/2009/08/21/ironscheme-clr-shorthand/

Will that work for you?

Cheers

leppie

 

Jan 5, 2010 at 3:21 PM

Hey,

So if i read the article correctly,

"clr-call, clr-field-get and clr-field-set! have been modified to infer the type based on the instance argument."

clr-call no longer requires an object type to be specified and instead uses reflection???

I would actually like to ruthelessly break all conventions too make a reader syntax that is short, sweet, and concise! Preferably, i would like to use dot notation though i noticed that one can't define anything with a dot

in it as a function name.

This is similar to clojure's notation. -->

(.methodName object arg1 arg2)--> calling a method on an object

(ClassName. arg1 ....) -->creating a class, expands to (new "ClassName" arg1 arg2) . So we have selective uppercase in our reader macro.

(.. object (method1 ...) (method 2)) --> equivalent to something like  object.method1(...).method2(...);

(%PropertyName object) and %Static.Property.Name

(set! (%PropertyName object) value) and (set! (%Static.PropertyName object) value) --> using set! extension

($FieldName object)  and $Static.Field.Name

(set! (%FieldName object) value) and (set! $Static.Field.Name value)

--------

So how much effort would be required to add in custom readtables per moduleX) Most of the above syntax would involve modifying the Open Parentheses , $, and % reader macros.

 

Coordinator
Jan 7, 2010 at 1:13 PM
Suroy wrote:

"clr-call, clr-field-get and clr-field-set! have been modified to infer the type based on the instance argument."

clr-call no longer requires an object type to be specified and instead uses reflection???

I does require it, but if you specify #f, it will try to be inferred (at compilation time, so no runtime reflection) based on the instance parameter.

This behaviour will start working better once I have more static typing happening. For now, it needs some kind of hint, like a property or a field.

Suroy wrote:

So how much effort would be required to add in custom readtables per moduleX) Most of the above syntax would involve modifying the Open Parentheses , $, and % reader macros.

Quite a lot, the least amount of effort would be to create a additional reader to expand the code to normalized s-expressions, so it can be read by the normal reader, which is completely inflexible as it is a generated lexical analyzer/parser.

So given a little thinking, one could do the following:

  1. Create some special compile time directive, ie #!clr (like the #!rnrs directive) to indicate a different reader
  2. Create a reader to expand code to normal s-expression
  3. Compile file as usual then

I will think about the idea a little more, but it should not be too hard, and will not break existing code  :)

Cheers

leppie