If you use global values, this should work:

SYMBOL: a
1 a set-global
"Press" [ drop a get-global ... ] <border-button> gadget.

The problem with "set" and "get", is that the 'set' is using the namespace
of the listener which may (likely not) be the namespace of the quotation
being executed by the quotation.  Namespaces are hierarchical, so you want
to make sure that the value is set in either the current scope or one of
the outer scopes to be accessible.

Does that make sense?

By the way, there are several ways to get your code to work, through
currying as was mentioned previously, namespaces like you are trying now,
or even subclassing a button and storing your value in a slot, e.g:

TUPLE: a-button < button a ;
: <a-button> ( label quot -- button )
    a-button new-button border-button-theme ;
"Press" [ a>> ... ] <a-button> 1 >>a gadget.

Best,
John.



On Tue, Dec 18, 2012 at 10:26 AM, Samuel Proulx <[email protected]>wrote:

> I've been experimenting with it and I now have another question.
>
> I've figured a way to use symbols in the quotations like so:
>
> SYMBOL: a
> 1 a set
> "Press" *a get* *'*[ drop *_* ... ] <border-button> gadget.
>
> I don't know if that's the best the way to do it but it works. Although,
> what I would like to do is to set the value of the symbol a from inside the
> quotation. How can I do that?
>
>
>
> 2012/12/17 Samuel Proulx <[email protected]>
>
>> I see! Thank you for your help and your explanations!
>>
>>
>> 2012/12/17 Jon Harper <[email protected]>
>>
>>> The quotation you pass to the <border-button> constructor gets called by
>>> the system when the button is pressed. At this time, the stack has nothing
>>> to do with the stack shown in the listener. So you don't have the reference
>>> to the label.
>>>
>>> To have a reference to the label when the quotation is called, you
>>> should make a closure. This can be done with "curry" (or, in this case, the
>>> more appropriate "with"):
>>>
>>> "Test" <label> dup gadget.
>>> "Press" [ drop "Worked" >>text drop ] with <border-button> gadget.
>>>
>>> Other ways of creating closures are fried quotations (
>>> http://docs.factorcode.org/content/article-fry.html) or local variables
>>> (http://docs.factorcode.org/content/article-locals.html)
>>>
>>> Cheers,
>>> Jon
>>>
>>>
>>>
>>> On Mon, Dec 17, 2012 at 10:48 PM, Samuel Proulx 
>>> <[email protected]>wrote:
>>>
>>>> Hi,
>>>>
>>>> Yet another problem... Hopefully the last though.
>>>>
>>>> I tried to make a button that changes the text slot of a previously
>>>> made label. Here's what I did:
>>>>
>>>> "Test" <label> dup gadget.
>>>> "Press" [ drop "Worked" >>text ] <border-button> gadget.
>>>>
>>>> I got an error message saying "Data stack underflow" when I clicked it.
>>>> So I checked the quotation stack effect:
>>>>
>>>> [ drop "Worked" >>text ] infer.
>>>> ( x x -- x )
>>>>
>>>> It should take the button, drop it since I don't need it, take the
>>>> label, and then change its text to "Worked". It doesn't do it though. What
>>>> did I do wrong?
>>>>
>>>> Thanks in advance,
>>>> Samuel
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
>>>> Remotely access PCs and mobile devices and provide instant support
>>>> Improve your efficiency, and focus on delivering more value-add services
>>>> Discover what IT Professionals Know. Rescue delivers
>>>> http://p.sf.net/sfu/logmein_12329d2d
>>>> _______________________________________________
>>>> Factor-talk mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
>>> Remotely access PCs and mobile devices and provide instant support
>>> Improve your efficiency, and focus on delivering more value-add services
>>> Discover what IT Professionals Know. Rescue delivers
>>> http://p.sf.net/sfu/logmein_12329d2d
>>> _______________________________________________
>>> Factor-talk mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>
>>>
>>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to