Question on temporal variables in Workspace

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on temporal variables in Workspace

nacho
Hi pharoers,
In killion video tutorials I see that he uses variables not declaring them as temporal (that is | aVariable | ).
If one does not declare variables as temporal in a workspace what kind of variables are them?
Also why in the tutorial they appear in blue and in my workspace they appear in red as if there was something wrong? (actually if I declare all variables as temporal using | | then all turn tu blue).
Thanks in advance and best regards
Nacho
Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Edward Povazan
I am a bit new to Pharo, anyone please correct me if I am wrong.

The Workspace has a #mustDeclareVariables: method. I am assuming it is set to false by default.
The colour changes once you DoIt on the code, as the variable is automatically created and bound to the workspace, so after running once, it exists. You can see this as the first time when you try inspect a variable, an error occurs. After DoIt, it changes colour, and you can inspect it.

Cheers,
-Edward

> On Dec 27, 2014, at 11:28 AM, nacho <[hidden email]> wrote:
>
> Hi pharoers,
> In killion video tutorials I see that he uses variables not declaring them
> as temporal (that is | aVariable | ).
> If one does not declare variables as temporal in a workspace what kind of
> variables are them?
> Also why in the tutorial they appear in blue and in my workspace they appear
> in red as if there was something wrong? (actually if I declare all variables
> as temporal using | | then all turn tu blue).
> Thanks in advance and best regards
> Nacho
>
>
>
>
> -----
> Nacho
> Smalltalker apprentice.
> Buenos Aires, Argentina.
> --
> View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

stepharo

> I am a bit new to Pharo, anyone please correct me if I am wrong.

excellent initiative.
Explaining  is an excellent way to learn.

> The Workspace has a #mustDeclareVariables: method. I am assuming it is set to false by default.
> The colour changes once you DoIt on the code, as the variable is automatically created and bound to the workspace, so after running once, it exists. You can see this as the first time when you try inspect a variable, an error occurs. After DoIt, it changes colour, and you can inspect it.
>
> Cheers,
> -Edward


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

kilon.alios
In reply to this post by nacho
I am not familiar with that part of Pharo because I never use temporary variables in Workspace but I did a little experiment and this is what I found . I followed these 3 steps

1) I created 2 Workspaces 
2) In first Workspace I put the code 

|a|
a:= Morph new.
a openInWindow .

3) In the second Workspace I put the code

a:= Morph new.
a openInWindow .

Now executing both examples give the result you would expect , a morph inside a window BUT if I inspect variable a in both cases , the workspace variable example returns me a Morph as to be expected on the other hand the workspace temporary variable returns me an undefined object. So that leads me to assume here that the temporary variable works as expect by destroying its reference as soon as the code is executed, hence why its called "temporary ;) 



On Sat, Dec 27, 2014 at 9:28 PM, nacho <[hidden email]> wrote:
Hi pharoers,
In killion video tutorials I see that he uses variables not declaring them
as temporal (that is | aVariable | ).
If one does not declare variables as temporal in a workspace what kind of
variables are them?
Also why in the tutorial they appear in blue and in my workspace they appear
in red as if there was something wrong? (actually if I declare all variables
as temporal using | | then all turn tu blue).
Thanks in advance and best regards
Nacho




-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Sven Van Caekenberghe-2
Kilon,

You figured out how to use it, yet you did not use the system to search for an explanation ?

From the class comment of Workspace:

===
A workspace can have its own variables, called "workspace variables", to hold intermediate results.  For example, if you type into a workspace "x := 5" and do-it, then later you could type in "y := x * 2" and y would become 10.
===

In the window menu of Workspace you have 'Inspect variables', 'Reset Variables'.

Check the references to the instance variable 'bindings' of Workspace.

Check the senders of #bindingOf:

Summary:

When evaluating code (do it, inspect it, print it) the expression is compiled. Compilation happens in a context. For scripting code this is often nil, but Pharo (method code) normally references an object (self). So when evaluating from a Workspace, the workspace instance with its bindings is used as context. So, these variables are local to the workspace, but behave a bit like a mixture between global and instance variables.

HTH,

Sven

> On 28 Dec 2014, at 09:32, kilon alios <[hidden email]> wrote:
>
> I am not familiar with that part of Pharo because I never use temporary variables in Workspace but I did a little experiment and this is what I found . I followed these 3 steps
>
> 1) I created 2 Workspaces
> 2) In first Workspace I put the code
>
> |a|
> a:= Morph new.
> a openInWindow .
>
> 3) In the second Workspace I put the code
>
> a:= Morph new.
> a openInWindow .
>
> Now executing both examples give the result you would expect , a morph inside a window BUT if I inspect variable a in both cases , the workspace variable example returns me a Morph as to be expected on the other hand the workspace temporary variable returns me an undefined object. So that leads me to assume here that the temporary variable works as expect by destroying its reference as soon as the code is executed, hence why its called "temporary ;)
>
>
>
> On Sat, Dec 27, 2014 at 9:28 PM, nacho <[hidden email]> wrote:
> Hi pharoers,
> In killion video tutorials I see that he uses variables not declaring them
> as temporal (that is | aVariable | ).
> If one does not declare variables as temporal in a workspace what kind of
> variables are them?
> Also why in the tutorial they appear in blue and in my workspace they appear
> in red as if there was something wrong? (actually if I declare all variables
> as temporal using | | then all turn tu blue).
> Thanks in advance and best regards
> Nacho
>
>
>
>
> -----
> Nacho
> Smalltalker apprentice.
> Buenos Aires, Argentina.
> --
> View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

kilon.alios
"You figured out how to use it, yet you did not use the system to search for an explanation ?"

Do you call me lazy ?

where you based this assumption ? I have looked in the past on the comment of the Workspace class but I dont find an adequate (as most class comments inside Pharo) to explain the inner workings of Workspace. Also I dont have the time ( I can only spare one hour a day ) to study the entire source code of Pharo , I read code only on the "need to know basis". I never felt the need to know how workspace variables work internally and whats their difference with temporary variables. 

"Check the references to the instance variable 'bindings' of Workspace."

if you read my post you would have noticed I have already done that. Unless you mean something else ? 

Also the title of this thread is "Temporary Variables" , I dont see you mentioning them anywhere . 

"When evaluating code (do it, inspect it, print it) the expression is compiled. Compilation happens in a context. For scripting code this is often nil, but Pharo (method code) normally references an object (self). So when evaluating from a Workspace, the workspace instance with its bindings is used as context. So, these variables are local to the workspace, but behave a bit like a mixture between global and instance variables."

I don't know how Nacho feels about this but I cant say it makes it clear for me how workspace variables vs workspace temporary variables work exactly. 

I have read about Squeak compilation model somewhere and the importance of thisContext , so I think I understand at least vaguely how this works. 

I have to say I find the term "scripting" perplexing. Scritping for me is coding that allows one to manipulate an application, but Pharo is more like a development enviroment so I dont see how it would be possible to do scripting inside Pharo using the pharo language.  


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Sven Van Caekenberghe-2

> On 28 Dec 2014, at 12:52, kilon alios <[hidden email]> wrote:
>
> "You figured out how to use it, yet you did not use the system to search for an explanation ?"
>
> Do you call me lazy ?

Hmm, I was only provoking you a little bit ;-)

What I meant is: it was a actually explained in the class comment, which is the first place to look for information. I know they are not all good, but at least here the thing you wanted to know was mentioned.

Second, the whole idea of Pharo is that you can explore the system using the tools given. I was just suggesting how you would/could do that. I did the same thing before writing the mail.

Of course, you do not have to read everything from beginning to end, no one would want to do that. You just start looking for specific information, poke the system. Once you get the hang of it, it is really cool and powerful.

There are some Pharo contributors who are amazingly good at this, fixing issues that must be new to them.

Sven


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

kilon.alios
this is the class comment of Workspace :

 <<< A Workspace is a text area plus a lot of support for executable code.  It is a great place to execute top-level commands to compute something useful, and it is a great place to develop bits of a program before those bits get put into class methods.

To open a new workspace, execute:

Workspace open


A workspace can have its own variables, called "workspace variables", to hold intermediate results.  For example, if you type into a workspace "x := 5" and do-it, then later you could type in "y := x * 2" and y would become 10.

Additionally, in Morphic, a workspace can gain access to morphs that are on the screen.  If acceptDroppedMorphss is turned on, then whenever a morph is dropped on the workspace, a variable will be created which references that morph.  This functionality is toggled with the window-wide menu of a workspace.



The instance variables of this class are:

bindings  -  holds the workspace variables for this workspace

acceptDroppedMorphss - whether dropped morphs should create new variables >>>


Call me blind but I dont see anywhere mentioning local/temporary variables and how they work diffirently for wokspace compared to just regular workspace variables. Because thats exactly what we discuss here. 

"Once you get the hang of it, it is really cool and powerful."

Indeed it get better and better, and I can see why pharo coders feel less need to rely on documentation compared to beginners like me and Nacho. The one thing that really annoy me with pharo is what I call "the happy Kangaroo" problem. That problem appears in some cases that one method depends on another which depends on the other etc etc that ends up a nasty spagettification .So trying to understand the code is like hunting down a happy Kangaroo.  This is where class comments can be really helpful to help you understand something that you wont get easily from reading method source. 

Actually I think this workspace comment is quite good, I have no issues with it, it just does not answer the question of this thread which is ok. I dont care about perfection. 


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

nacho
In reply to this post by kilon.alios
First of all thanks for all the responses. I should have checked the class comment first.

I agree with Kilon, if I use a temporary variable in a workspace after doing the code if I inspect it the object is gone whereas doing it the way Kilon does the object is still there.
Now why in my Pharo images Workspace variable (I suppose this is the correct term isn't it?) are in red and in Kilon's awesome tutorials are in blue?
best regards
Nacho

Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Sven Van Caekenberghe-2
In reply to this post by kilon.alios

On 28 Dec 2014, at 14:26, kilon alios <[hidden email]> wrote:

Call me blind but I dont see anywhere mentioning local/temporary variables and how they work diffirently for wokspace compared to just regular workspace variables. Because thats exactly what we discuss here. 

Well, maybe the comment should have made a reference to temporary variables.

So instead of

===
A workspace can have its own variables, called "workspace variables", to hold intermediate results.  For example, if you type into a workspace "x := 5" and do-it, then later you could type in "y := x * 2" and y would become 10.
===

maybe

===
A workspace can have its own variables, called "workspace variables", to hold intermediate results.  For example, if you type into a workspace "x := 5" and do-it, then later you could type in "y := x * 2" and y would become 10.  Workspace variables are like temporary variables that you normally declare using |x| - the difference is that they are declared automatically on use and only exist in the scope of a particular workspace.
===

The colours used by syntax highlighting are customisable. Apart from that the highlighting can be a bit flaky.


The red should become blue once the variable is in use, it does do, but not reliably.

Sven
Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

kilon.alios
In reply to this post by nacho
yes that is an issue I have as well and it seems that it also continues in Pharo 4 Playground. But generally should not affect your code. 

On Sun, Dec 28, 2014 at 4:32 PM, nacho <[hidden email]> wrote:
First of all thanks for all the responses. I should have checked the class
comment first.

I agree with Kilon, if I use a temporary variable in a workspace after doing
the code if I inspect it the object is gone whereas doing it the way Kilon
does the object is still there.
Now why in my Pharo images Workspace variable (I suppose this is the correct
term isn't it?) are in red and in Kilon's awesome tutorials are in blue?
best regards
Nacho





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161p4797208.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Edward Povazan
Interesting - when I use Playground, the variable is red at first. After the first doit, it turns blue, I assume because it is now bound to an object. When I inspect after the initial doit, I get an inspector with the real object.
So ... installing GToolkit on Pharo 3 is the answer :)

-Edward

On Dec 28, 2014, at 10:23 AM, kilon alios <[hidden email]> wrote:

yes that is an issue I have as well and it seems that it also continues in Pharo 4 Playground. But generally should not affect your code. 

On Sun, Dec 28, 2014 at 4:32 PM, nacho <[hidden email]> wrote:
First of all thanks for all the responses. I should have checked the class
comment first.

I agree with Kilon, if I use a temporary variable in a workspace after doing
the code if I inspect it the object is gone whereas doing it the way Kilon
does the object is still there.
Now why in my Pharo images Workspace variable (I suppose this is the correct
term isn't it?) are in red and in Kilon's awesome tutorials are in blue?
best regards
Nacho





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161p4797208.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

Tudor Girba-2
Hi,

The current behavior, which indeed is preserved in the Playground because we did not get to revisit it yet, is like that:
- if you do not define a variable explicitly, it will appear red.
- if you run the code, the variable will be automatically define within the scope of the Playground/Workspace object which lives as long as the window does
- thus, essentially you get a kind of a persistent variable that survives an execution
- that is the reason why you can inspect the variable and get the result that it has accumulated
- one source of confusion is that after you run the code, the variable still remains red. However, after you type one character, it gets blue.

Ideally, we should have a more interactive way of defining variables and have an overview available at all times.

Cheers,
Doru



On Mon, Dec 29, 2014 at 1:27 AM, Edward Povazan <[hidden email]> wrote:
Interesting - when I use Playground, the variable is red at first. After the first doit, it turns blue, I assume because it is now bound to an object. When I inspect after the initial doit, I get an inspector with the real object.
So ... installing GToolkit on Pharo 3 is the answer :)

-Edward

On Dec 28, 2014, at 10:23 AM, kilon alios <[hidden email]> wrote:

yes that is an issue I have as well and it seems that it also continues in Pharo 4 Playground. But generally should not affect your code. 

On Sun, Dec 28, 2014 at 4:32 PM, nacho <[hidden email]> wrote:
First of all thanks for all the responses. I should have checked the class
comment first.

I agree with Kilon, if I use a temporary variable in a workspace after doing
the code if I inspect it the object is gone whereas doing it the way Kilon
does the object is still there.
Now why in my Pharo images Workspace variable (I suppose this is the correct
term isn't it?) are in red and in Kilon's awesome tutorials are in blue?
best regards
Nacho





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Question-on-temporal-variables-in-Workspace-tp4797161p4797208.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.





--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: Question on temporal variables in Workspace

nacho
Thanks Doru,
That was perfectly clear.
Best
Nacho
Nacho Smalltalker apprentice. Buenos Aires, Argentina.