Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline mkraska  
#1 Posted : 27 April 2014 10:34:50(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,990
Germany

Was thanked: 1128 time(s) in 724 post(s)
I was wondering if it is really necessary to provide the function arguments in uni's linq example both with the right names in the inline assignmants and with the right position in the argument list. And in fact, sometimes you really can mix the order. However, this does not work always and I am not able to find an explanation, when this works and when it does not. Another issue which adds complexity is the question, which of the inline definitions is visible outside.

This provides limitless options to hide your design intent from uninitiated outsiders.

Edited by user 27 April 2014 10:37:43(UTC)  | Reason: Not specified

File Attachment(s):
fun with functions.sm (42kb) downloaded 24 time(s).
mkraska attached the following image(s):
select.PNG
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 4 users thanked mkraska for this useful post.
on 27/04/2014(UTC),  on 27/04/2014(UTC),  on 27/04/2014(UTC),  on 27/04/2014(UTC)

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline omorr  
#2 Posted : 27 April 2014 13:14:25(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
I suppose most of us remained puzzled now Wallbash Crazy
As you said - s... happens Shok

To be honest, I myself am very surprised that never crossed my mind to try putting some inline assignment in the function call.

Although there might be some logic here, I find it rather confusing and hard to follow

Regards,
Radovan

Edited by user 27 April 2014 13:42:00(UTC)  | Reason: Not specified

omorr attached the following image(s):
inline.png
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
thanks 1 user thanked omorr for this useful post.
on 27/04/2014(UTC)
Offline mikekaganski  
#3 Posted : 27 April 2014 13:59:01(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Maybe it's like this: first step is assigning all formal variables their symbolic values by place, then evaluate all symbolic values from left to right, executing all side-effects (possibly overwriting previously calculated params when name is reassigned):

f(x:=10; z:=20; y:=3)
=step 1=> x->x:=10; y->z:=20; z->y:=3
=step 2=> x=<result of evaluating x:=10>
=step 3=> y=<result of evaluating z:=20> - here y is 20, AND z is 20
=step 4=> z=<result of evaluating y:=3> - here z is 3, AND y is 3!

This explains all Radovan's samples, but not Martin's. Here's why.

select(`(x):=x^2;`v:=(1..4))
=step 1=> `v->`(x):=x^2; `->`v:=(1..4)
=step 2=> `v=<result of evaluating `(x):=x^2> - here TWO functions are created: `(x) AND `v(x)! - EDIT: not true. Only one function `(x)=x^2, and one variable `v=x^2.
=step 3=> `=<result of evaluating `v:=(1..4)> - here TWO vector variables are created: `v AND `! So, TWO entities names ` coexist at this time: a function and a variable.
smath allows having many entities of same name: a variable and a number of functions having different number of args (overloading).
In select, then, only vector `v and function `(x) are used.

Edited by user 27 April 2014 15:13:18(UTC)  | Reason: Not specified

Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 27/04/2014(UTC)
Offline mikekaganski  
#4 Posted : 27 April 2014 14:56:33(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
f:=(f(x):=x^2)
f(2)=4
f=error: x - not defined
x:=3
f=9

Note that here two entities are defined: a function f(x)=x^2, and a scalar variable f=x^2. I believe that uni's approach to use ` as a lambda name creates the same effect: in his functions, there always exist a variable named ` (that is never used), and when this argument is assigned "lambda" like '(x):=x^2, this creates another function-local (?) entity (function) named `(x), that uni uses.
And that means that uni could use just any name for the formal arg there, but only require that lambda be named `, like here:

x:3

f(a;Cool:line(trace(a);`(Cool;2;1)

f(`(x):x^2;2)=4

(note that I must use ` in second line, while the formal arg is names a)
NB: trace output: a = 9!

I imagine what effects could this techinque introduce by changing some names used by function internally...

Edited by user 27 April 2014 15:18:34(UTC)  | Reason: Not specified

Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 27/04/2014(UTC)
Offline uni  
#5 Posted : 27 April 2014 15:08:23(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,495
Man
Russian Federation

Was thanked: 1275 time(s) in 746 post(s)
Very interesting things you wrote here, guys. I want only to say what I choosed ` symbol because in this case the equation has view which is similiar to original lamdba definition: (x) => x^2. And we have `(x) := x^2. Nothing else.

EDIT: As for the local vars. In first version I used _, but I changed it to ` because this likes me more. Usually you use _x for locals, but I used `x for short.
EDIT2: (x) => ... - must be an implicit function and when we write `(x) := ... it looks like a function without name ( "implicit" ).

Edited by user 27 April 2014 15:25:09(UTC)  | Reason: Not specified

Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 27/04/2014(UTC)
Offline mkraska  
#6 Posted : 27 April 2014 15:27:29(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,990
Germany

Was thanked: 1128 time(s) in 724 post(s)
Thank you all for your explanations. The explanations by Mike seem to be consistent with the observed return values. The side effects might be consistent with output parameter handling, once you see everything but step 1 in Mike's explanations as part of the function body. But I did not yet verify that.

My impression is that we need a function call syntax without any name restrictions. If at a certain position a function is expected, any pre-defined or inline-assigned function of any or without name should do. Formal parameter names must be strictly shielded from global namespace.

Edited by user 27 April 2014 15:43:10(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline mikekaganski  
#7 Posted : 27 April 2014 15:53:22(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: mkraska Go to Quoted Post
If at a certain position a function is expected, any pre-defined or inline-assigned function of any or without name should do.


Note that function as parameter is another syntax: f(g(2)...):=... or f(g(a;b;c)...):=... where a, b and c are uninitialized at the time of definition. It's covered here.

That approach is somewhat limited, I'd say it's not ready for prime-time yet, that's why this uni's technique is required (and invaluable to workaround, say, SS-123).
Best regards,
Mike Kaganski
Offline mkraska  
#8 Posted : 01 May 2014 14:26:52(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,990
Germany

Was thanked: 1128 time(s) in 724 post(s)
Here is an attempt to summarize part of the discussion. Not yet covered:
- analysis of what happens if there are name coincidences in the function call and in the list of the formal parameters, including effects of evaluation order
- side effects of inline definitions
- and much more...
File Attachment(s):
Section Prog functions.sm (24kb) downloaded 30 time(s).
Section Prog functions as arguments.sm (22kb) downloaded 29 time(s).
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.