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 Jean Giraud  
#1 Posted : 22 January 2016 20:04:32(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: ioan92 Go to Quoted Post
" A call-by-reference language makes it more difficult for a programmer to track the effects of a function call, and may introduce subtle bugs."
.

_________________ Agree ............

That happened many times in the Mathsoft Collaboratory, especially wrt languages accents".
Not in French because Mathcad 8 was in French as well. But commonly with Czechoslovakia and
Russia. In fact, Valery "Mathcad online server" often failed to open or got coco.

Your attachment crashes version 5346.

The best example of buggy encapsulation is Microsoft.
When you close a work sheet, Windows encapsulates the work sheet stuff.
It created an enormous amount of typos in "Times new Roman".
Curiously, Smath that is "Courier" does not create typo errors.

Encapsulation: NFG

Salut Ioan, Jean

BTW: revisit the latest "Vectorise", works fine but no operator
For an operator, more coding is neded from Andrey.




thanks 1 user thanked Jean Giraud for this useful post.
on 22/01/2016(UTC)

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

Offline Davide Carpi  
#2 Posted : 22 January 2016 20:57:55(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
Hello Ioan,

Originally Posted by: ioan92 Go to Quoted Post
Allthough, I think that it could be benefic for all to reiterate the subject as it is now.

I agree Good

The behavior is:

  1. a variable name defined as input of a function (argument of the function) is a local variable of the function (global for sub-levels of the function made by using line());
    Inside the function every time you use that name, the values passed as argument are used; doesn't matter if there is a variable with the same outside the function. In other words, declaring that name as input parameter you override (locally) any variable defined in the parent levels.

    examples

  2. variables not defined as input of a function or hidden inside another variable, are searched from the parent(s) level

    f(A)=A+b+3 -> if available b is taken going up through the parent levels (the canvas if you don't have nested line()).

  3. If inside the function you use the input as target of the changes, the input changes (call by reference)
    This may be really powerful; f.e. you can process several variables with a single function, using the result of the function for checks or to have more results.

    examples (pseudocode)

Edited by user 22 January 2016 21:34:26(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 22/01/2016(UTC)
Offline Davide Carpi  
#3 Posted : 23 January 2016 02:26:47(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
Originally Posted by: ioan92 Go to Quoted Post
I wonder if it could not be a more beneficial a fully encapsulated solution (using by value reference):

* to introduce data only by the function parameters, without touching this variables for the appellant segment;
* all function internal variables to be viewed exclusively inside the function;
* the function output to be only that declared by the output line.


In this way, maybe the creatively side would be diminished, but the robustness in use will increase?


Robustness: yes, obviously. On the other hand you loose flexibility, compactness [you have to pass any input value to the function; f.e. for the simple σ(N,M.x,M.y):N/A+M.x/W.x+M.y/W.y --> σ(N,A,M.x,M.y,W.x,W.y):N/A+M.x/W.x+M.y/W.y], and performances in speed and memory (a deep copy - the copy of the values - would be needed for any variable passed as input -> more inputs = more operations).

May be matter of taste, however I think it is not so complicated to deal with these features (just a personal opinion).

Edited by user 23 January 2016 02:33:41(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 23/01/2016(UTC)
Offline Jean Giraud  
#4 Posted : 23 January 2016 06:43:16(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
The primary purpose of encapsulation was to restrict user from
reverse engineer coding. So, a gear like Mathematica 4.0 as they
though they invented grafting wings on stones, their encapsulated
stuff can't be QA checked, neither it allows user to expand/adapt
the designed capsule. The pros will acert increase in speed.
No so sure of that: Mathematica 4.0 is steam engine vs TGV [Mathcad 11]

Smath is a continuous encapsulator,
of DATA, no matter the name of the
argument because they reflect.
DATA are not parametric. That's why
I can't reproduce De Casteljau svg
algorithm.

Jean

Untitled Encapsulation.sm (9kb) downloaded 36 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 23/01/2016(UTC)
Offline RFreund  
#5 Posted : 23 January 2016 18:33:44(UTC)
RFreund


Rank: Advanced Member

Groups: Registered
Joined: 25/09/2013(UTC)
Posts: 325
United States
Location: IL

Was thanked: 19 time(s) in 17 post(s)
Wow! Ioan thank you for bring this to light (atleast for me). It was if you were speaking directly to me.

After reading this my main takeaway is that if you change one of you input variables inside your function, it will be changed outside your function.
I still like the idea of using # or other variables inside the function just to keep things clear however you are correct that it doesn't do much good if you are altering your input parameters.

I think for the most part my functions are "safe" as I normally do not alter the input parameters but it is not something I had previously considered.

Davide ->
I'm not sure I quite understand your example of why this is useful (I trust you but I just don't seem to follow, maybe I need to ponder this longer...). Why can't the variables remain as 'local' and be passed into the "check" function. Here is an example of what I mean:
http://smath.info/cloud/sheet/2e4L7Mh7VQ
thanks 2 users thanked RFreund for this useful post.
on 23/01/2016(UTC),  on 23/01/2016(UTC)
Offline Davide Carpi  
#6 Posted : 23 January 2016 21:29:20(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
Originally Posted by: RFreund Go to Quoted Post
I still like the idea of using # or other variables inside the function just to keep things clear however you are correct that it doesn't do much good if you are altering your input parameters.

I agree, it is a good practice.

Originally Posted by: RFreund Go to Quoted Post
I'm not sure I quite understand your example of why this is useful (I trust you but I just don't seem to follow, maybe I need to ponder this longer...). Why can't the variables remain as 'local' and be passed into the "check" function.


In general, they can (was the behavior of SMath < 0.90).

I think most of the confusion it's my fault; writing my answer I've focused my attention too much on the Ioan's proposal part "to introduce data only by the function parameters", mixing things in a bad way and loosing the point;

Things to point out:

  1. The names of variables (including names of input arguments) are local;

  2. "global" variables can be accessed from inside the function and modified locally without changes outside the function (Ioan's example: point 2; this is a pass-by-value under the hood, when an unknown for the line() workspace can be found in the parent levels);

  3. the pass-by-reference feature triggers effects only if you assign values to an input variable (function's arguments) (as you have written, for most of the normal applications input parameters are untouched, this is matter of advanced uses like implicit functions);

  4. it is possible to use the name of a global variable to define a local variable; since locally is no more an unknown, the function from that point doesn't search it in the parent level.


In general, pass-by-reference it keeps a bidirectional channel between the function workspace and the parent level(s); this is cheaper in speed and memory because you don't have to make 2 copies of the variable and the output of the function can be lighter; this is good also for the syntax too, because there are less assignments to make outside the function (this also improves the speed, having less assignments - that are basically copy & destroy actions - pass-by-values).

Note that before SMath 0.90 functions + lines were are all working with pass-by-values (and globals were available as it is now); this feature was introduced in SMath 0.90 to improve functionality like graphs animation, but allows also other stuff (look at the ChordMethod provided by Andrey in the link).

Pass by reference may be tricky but it is part of almost all the programming languages, and often is the default way to pass objects (in the .NET Framework f.e. strings, arrays, class types are passed by reference; numbers, booleans by value).

Edited by user 23 January 2016 23:26:51(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 23/01/2016(UTC)
Offline Jean Giraud  
#7 Posted : 24 January 2016 22:47:17(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: ioan92 Go to Quoted Post
I practiced this much, more as a "wise" precaution, see as a "religion", without knowing if this really matters or no.
I felt this as a sort punishment to load each variable name inside a function with a unnecessarily character.


In a definition such as f(x):= ln(x) [per ay] 'f' the alago name is the procedure
identifier of the RHS [Right Hand Side]. It belongs to the numerical suite.
'x' is a local "scalar", which "scalar" is not a number as usually understood,
NO: it is a local numerical vanishing iterator. It can be anything you want as it
does not perspire elsewhwere in the system. Nuance: Smath quick plot takes only
'x' as the canvas filler.
In Smath as well as Mathcad, f(x) can be reused indefinitely, whereas each RHS
is independently identified, and running locally on the vanishing 'x'.
In other words, only the RHS is encapsulated [so to speak].
The other story is Smath does not overwrite over a matrix. You can't reuse
'M' in a work sheet unlike Mathcad. However, in Mathcad if the second time
you use 'M' if shorter than the frst one, the 2nd will remain full of the
data from the pevious one ... Mathsoft was saying "watch were you thread".
The story is much longer than just as you read.

Jean

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.