+1, default value is needed. Basically direct call to trap is sort of reflection for dynamic invocations. For example, I have a Json object (map with overrided trap) and use it like this:
So in all cases when I know the name, everything is fine, I use -> and don't care about default parameter. Buf if names are coming from somewhere, I need to either expose map from my json obj, or call trap directly.
Some random example: imagine I need to get certain fields from list of objects and display them in a table, I have to write something like this:
Another thought on trap - probably it could be better to have separate methods like trapGet, trapSet and trapCall:
Such separation needs to be done in overriden trap manually in most cases
Right now inside the trap we can distinguish getting from setting and calling just by arg count. However there's no direct way to separate setter and call.
Compiler already has all this information, so it should be easy
vkuzkokovFri 24 Dec 2010
Another thought on trap - probably it could be better to have separate methods like > trapGet, trapSet and trapCall
Not really. trapGet and trapCall with no parameters are intentionally indistinguishable, so that we could override no-param method with a field.
If W3 Schools is to be believed. Nice use of map and join, though.
brianSun 2 Jan 2011
Renamed from **[idea] add default to parameter args in Obj.trap** to **Obj.trap support for default args of null**
brianSun 2 Jan 2011
Promoted to ticket #1363 and assigned to brian
brianSun 2 Jan 2011
I made two changes regarding this issue:
Obj.trap now defaults the args parameter to null when using trap explicitly
Compiler now passes null for x->y and x->y() when there are no arguments
The second fix is an optimization since previously I was actually allocating an unnecessary empty list. Might be a gotcha for some trap implementations that weren't handling null correctly.
Akcelisto Thu 23 Dec 2010
change to
yachris Thu 23 Dec 2010
What problem does this solve?
Akcelisto Fri 24 Dec 2010
This is save six keystrokes!
vs
ivan Fri 24 Dec 2010
+1, default value is needed. Basically direct call to trap is sort of reflection for dynamic invocations. For example, I have a Json object (map with overrided
trap
) and use it like this:So in all cases when I know the name, everything is fine, I use
->
and don't care about default parameter. Buf if names are coming from somewhere, I need to either expose map from my json obj, or calltrap
directly.Some random example: imagine I need to get certain fields from list of objects and display them in a table, I have to write something like this:
Another thought on trap - probably it could be better to have separate methods like
trapGet
,trapSet
andtrapCall
:trap
manually in most casestrap
we can distinguish getting from setting and calling just by arg count. However there's no direct way to separate setter and call.vkuzkokov Fri 24 Dec 2010
Not really.
trapGet
andtrapCall
with no parameters are intentionally indistinguishable, so that we could override no-param method with a field.yachris Fri 24 Dec 2010
Actually,
th
is a replacement fortd
, nottr
. I think you wantIf W3 Schools is to be believed. Nice use of map and join, though.
brian Sun 2 Jan 2011
Renamed from **[idea] add default to parameter args in Obj.trap** to **Obj.trap support for default args of null**
brian Sun 2 Jan 2011
Promoted to ticket #1363 and assigned to brian
brian Sun 2 Jan 2011
I made two changes regarding this issue:
x->y
andx->y()
when there are no argumentsThe second fix is an optimization since previously I was actually allocating an unnecessary empty list. Might be a gotcha for some trap implementations that weren't handling null correctly.
brian Sun 2 Jan 2011
Ticket resolved in 1.0.57
go4 Fri 14 Jan 2011
What about empty list const? like
List.empty