Re: How do I translate Javascript constructors to Amber Smalltalk code?

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

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk

Link corrected.

On 4/28/14, H. Hirzel <[hidden email]> wrote:

> Hello
>
> I put a question here
>
> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>
> Answers to the ML are welcome as well of course.
>
> Regards and best wishes for a happy Amber coding week
>
> Hannes
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
Hello,

I found the answer myself and put it on stackoverflow.

 Now to a more extended question:

What is wrong with the following translation

Code from
https://github.com/hhzl/Amber-Paper-Demo/blob/master/src/Examples-Paper.st

Paper mainJS evaluated in a workspace works.
Paper main (= the Amber version) does not.

--Hannes


------------------------------------------------------------------------------------------------------------

Object subclass: #Paper2
instanceVariableNames: ''
package: 'Examples-Paper'!

!Paper2 class methodsFor: 'not yet classified'!

main
| canvas aPath start |
   canvas := document getElementById: 'myCanvas'.

   "Create an empty project and a view for the canvas:"
    paper setup: canvas.

    aPath := (paper Path) new.

"Give the stroke a color"
aPath inspect.

"aPath strokeColor: 'red'."

start := (paper Point) newValue: 100 value: 200.

aPath moveTo: start.

aPath lineTo: (start add: { 200. -50 }).

paper view draw.
!

mainJS
<
// Get a reference to the canvas object
var canvas = document.getElementById('myCanvas');
// Create an empty project and a view for the canvas:
paper.setup(canvas);
// Create a Paper.js Path to draw a line into it:
var path = new paper.Path();
// Give the stroke a color
path.strokeColor = 'black';
var start = new paper.Point(100, 100);
// Move to start and draw a line from there
path.moveTo(start);
// Note that the plus operator on Point objects does not work
// in JavaScript. Instead, we need to call the add() function:
path.lineTo(start.add([ 200, -50 ]));
// Draw the view now:
paper.view.draw();
>
! !


On 4/28/14, H. Hirzel <[hidden email]> wrote:

> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>
> Link corrected.
>
> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>> Hello
>>
>> I put a question here
>>
>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>
>> Answers to the ML are welcome as well of course.
>>
>> Regards and best wishes for a happy Amber coding week
>>
>> Hannes
>>
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
Thank you Herby and Sebastian for your help with

http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk

I think the answer should be fine now . May I ask others for feedback
(votes and comments)?

I am still figuring out how to translate more complex expressions as JavaScript

   path.lineTo(start.add([ 200, -50 ]));

--Hannes

On 4/28/14, H. Hirzel <[hidden email]> wrote:

> Hello,
>
> I found the answer myself and put it on stackoverflow.
>
>  Now to a more extended question:
>
> What is wrong with the following translation
>
> Code from
> https://github.com/hhzl/Amber-Paper-Demo/blob/master/src/Examples-Paper.st
>
> Paper mainJS evaluated in a workspace works.
> Paper main (= the Amber version) does not.
>
> --Hannes
>
>
> ------------------------------------------------------------------------------------------------------------
>
> Object subclass: #Paper2
> instanceVariableNames: ''
> package: 'Examples-Paper'!
>
> !Paper2 class methodsFor: 'not yet classified'!
>
> main
> | canvas aPath start |
>    canvas := document getElementById: 'myCanvas'.
>
>    "Create an empty project and a view for the canvas:"
>     paper setup: canvas.
>
>     aPath := (paper Path) new.
>
> "Give the stroke a color"
> aPath inspect.
>
> "aPath strokeColor: 'red'."
>
> start := (paper Point) newValue: 100 value: 200.
>
> aPath moveTo: start.
>
> aPath lineTo: (start add: { 200. -50 }).
>
> paper view draw.
> !
>
> mainJS
> <
> // Get a reference to the canvas object
> var canvas = document.getElementById('myCanvas');
> // Create an empty project and a view for the canvas:
> paper.setup(canvas);
> // Create a Paper.js Path to draw a line into it:
> var path = new paper.Path();
> // Give the stroke a color
> path.strokeColor = 'black';
> var start = new paper.Point(100, 100);
> // Move to start and draw a line from there
> path.moveTo(start);
> // Note that the plus operator on Point objects does not work
> // in JavaScript. Instead, we need to call the add() function:
> path.lineTo(start.add([ 200, -50 ]));
> // Draw the view now:
> paper.view.draw();
>>
> ! !
>
>
> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>>
>> Link corrected.
>>
>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>> Hello
>>>
>>> I put a question here
>>>
>>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>>
>>> Answers to the ML are welcome as well of course.
>>>
>>> Regards and best wishes for a happy Amber coding week
>>>
>>> Hannes
>>>
>>
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Nicolas Petton

H. Hirzel writes:

> I am still figuring out how to translate more complex expressions as JavaScript
>
>    path.lineTo(start.add([ 200, -50 ]));

path lineTo: (start add: #(200 -50))

Nico

>
> --Hannes
>
> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>> Hello,
>>
>> I found the answer myself and put it on stackoverflow.
>>
>>  Now to a more extended question:
>>
>> What is wrong with the following translation
>>
>> Code from
>> https://github.com/hhzl/Amber-Paper-Demo/blob/master/src/Examples-Paper.st
>>
>> Paper mainJS evaluated in a workspace works.
>> Paper main (= the Amber version) does not.
>>
>> --Hannes
>>
>>
>> ------------------------------------------------------------------------------------------------------------
>>
>> Object subclass: #Paper2
>> instanceVariableNames: ''
>> package: 'Examples-Paper'!
>>
>> !Paper2 class methodsFor: 'not yet classified'!
>>
>> main
>> | canvas aPath start |
>>    canvas := document getElementById: 'myCanvas'.
>>
>>    "Create an empty project and a view for the canvas:"
>>     paper setup: canvas.
>>
>>     aPath := (paper Path) new.
>>
>> "Give the stroke a color"
>> aPath inspect.
>>
>> "aPath strokeColor: 'red'."
>>
>> start := (paper Point) newValue: 100 value: 200.
>>
>> aPath moveTo: start.
>>
>> aPath lineTo: (start add: { 200. -50 }).
>>
>> paper view draw.
>> !
>>
>> mainJS
>> <
>> // Get a reference to the canvas object
>> var canvas = document.getElementById('myCanvas');
>> // Create an empty project and a view for the canvas:
>> paper.setup(canvas);
>> // Create a Paper.js Path to draw a line into it:
>> var path = new paper.Path();
>> // Give the stroke a color
>> path.strokeColor = 'black';
>> var start = new paper.Point(100, 100);
>> // Move to start and draw a line from there
>> path.moveTo(start);
>> // Note that the plus operator on Point objects does not work
>> // in JavaScript. Instead, we need to call the add() function:
>> path.lineTo(start.add([ 200, -50 ]));
>> // Draw the view now:
>> paper.view.draw();
>>>
>> ! !
>>
>>
>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>>>
>>> Link corrected.
>>>
>>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>>> Hello
>>>>
>>>> I put a question here
>>>>
>>>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>>>
>>>> Answers to the ML are welcome as well of course.
>>>>
>>>> Regards and best wishes for a happy Amber coding week
>>>>
>>>> Hannes
>>>>
>>>
>>


--
Nicolas Petton
http://nicolas-petton.fr

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
Thank you, Nicolas. No syntax error.

However the whole thing https://github.com/hhzl/Amber-Paper-Demo still
does not work for some reason


Paper2>>main


| canvas aPath start |
   canvas := document getElementById: 'myCanvas'.

   "Create an empty project and a view for the canvas:"
    paper setup: canvas.
       
    aPath := (paper Path) new.
       
        "Give the stroke a color"
        aPath inspect.
       
        "aPath strokeColor: 'red'."
       
        start := (paper Point) newValue: 100 value: 200.
       
        aPath moveTo: start.
       
        aPath lineTo: (start add: #(200 -50)).
        paper view draw.
       

--Hannes

On 4/28/14, Nicolas Petton <[hidden email]> wrote:

>
> H. Hirzel writes:
>
>> I am still figuring out how to translate more complex expressions as
>> JavaScript
>>
>>    path.lineTo(start.add([ 200, -50 ]));
>
> path lineTo: (start add: #(200 -50))
>
> Nico
>
>>
>> --Hannes
>>
>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>> Hello,
>>>
>>> I found the answer myself and put it on stackoverflow.
>>>
>>>  Now to a more extended question:
>>>
>>> What is wrong with the following translation
>>>
>>> Code from
>>> https://github.com/hhzl/Amber-Paper-Demo/blob/master/src/Examples-Paper.st
>>>
>>> Paper mainJS evaluated in a workspace works.
>>> Paper main (= the Amber version) does not.
>>>
>>> --Hannes
>>>
>>>
>>> ------------------------------------------------------------------------------------------------------------
>>>
>>> Object subclass: #Paper2
>>> instanceVariableNames: ''
>>> package: 'Examples-Paper'!
>>>
>>> !Paper2 class methodsFor: 'not yet classified'!
>>>
>>> main
>>> | canvas aPath start |
>>>    canvas := document getElementById: 'myCanvas'.
>>>
>>>    "Create an empty project and a view for the canvas:"
>>>     paper setup: canvas.
>>>
>>>     aPath := (paper Path) new.
>>>
>>> "Give the stroke a color"
>>> aPath inspect.
>>>
>>> "aPath strokeColor: 'red'."
>>>
>>> start := (paper Point) newValue: 100 value: 200.
>>>
>>> aPath moveTo: start.
>>>
>>> aPath lineTo: (start add: { 200. -50 }).
>>>
>>> paper view draw.
>>> !
>>>
>>> mainJS
>>> <
>>> // Get a reference to the canvas object
>>> var canvas = document.getElementById('myCanvas');
>>> // Create an empty project and a view for the canvas:
>>> paper.setup(canvas);
>>> // Create a Paper.js Path to draw a line into it:
>>> var path = new paper.Path();
>>> // Give the stroke a color
>>> path.strokeColor = 'black';
>>> var start = new paper.Point(100, 100);
>>> // Move to start and draw a line from there
>>> path.moveTo(start);
>>> // Note that the plus operator on Point objects does not work
>>> // in JavaScript. Instead, we need to call the add() function:
>>> path.lineTo(start.add([ 200, -50 ]));
>>> // Draw the view now:
>>> paper.view.draw();
>>>>
>>> ! !
>>>
>>>
>>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>>> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>>>>
>>>> Link corrected.
>>>>
>>>> On 4/28/14, H. Hirzel <[hidden email]> wrote:
>>>>> Hello
>>>>>
>>>>> I put a question here
>>>>>
>>>>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>>>>
>>>>> Answers to the ML are welcome as well of course.
>>>>>
>>>>> Regards and best wishes for a happy Amber coding week
>>>>>
>>>>> Hannes
>>>>>
>>>>
>>>
>
>
> --
> Nicolas Petton
> http://nicolas-petton.fr
>
> --
> You received this message because you are subscribed to the Google Groups
> "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Vicnet-2
In reply to this post by Hannes Hirzel
Hello,

Wath do you think to add a link on wiki page on javascrit constructor
https://github.com/amber-smalltalk/amber/wiki/Call-javascript-constructors-with-arguments
into general wiki page on converting js to st
https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back

And also add the page link on literral notation
https://github.com/amber-smalltalk/amber/wiki/Literal-notation
on the same page.
because theses notations could be used directly in js code (hashedcollection as js dict).
(I use it to pass configuration to tsv papa parser)

a+
Vicnet
Le lundi 28 avril 2014 12:08:57 UTC+2, Hannes a écrit :
<a href="http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F23337995%2Fhow-do-i-translate-javascript-constructors-to-amber-smalltalk\46sa\75D\46sntz\0751\46usg\75AFQjCNFQoz_0edOLBcf6C8hE9WifQTsUZA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F23337995%2Fhow-do-i-translate-javascript-constructors-to-amber-smalltalk\46sa\75D\46sntz\0751\46usg\75AFQjCNFQoz_0edOLBcf6C8hE9WifQTsUZA';return true;">http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk

Link corrected.

On 4/28/14, H. Hirzel <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="HDy5IIIdDKQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">hannes...@...> wrote:

> Hello
>
> I put a question here
>
> <a href="http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F23337995%2Fhow-do-i-translated-javascript-constructors-to-amber-smalltalk\46sa\75D\46sntz\0751\46usg\75AFQjCNG7B_iSJrhx5U01K2OF2UEzceUWSw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F23337995%2Fhow-do-i-translated-javascript-constructors-to-amber-smalltalk\46sa\75D\46sntz\0751\46usg\75AFQjCNG7B_iSJrhx5U01K2OF2UEzceUWSw';return true;">http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>
> Answers to the ML are welcome as well of course.
>
> Regards and best wishes for a happy Amber coding week
>
> Hannes
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
Vicnet

Thank you for the feedback. That is great! The wiki is yours as well.
So you might as well just go ahead and do it

Can you give some more information what you are doing with the 'papa parser'?

--Hannes

On 4/28/14, Vicnet <[hidden email]> wrote:

> Hello,
>
> Wath do you think to add a link on wiki page on javascrit constructor
> https://github.com/amber-smalltalk/amber/wiki/Call-javascript-constructors-with-arguments
> into general wiki page on converting js to st
> https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>
> And also add the page link on literral notation
> https://github.com/amber-smalltalk/amber/wiki/Literal-notation
> on the same page.
> because theses notations could be used directly in js code
> (hashedcollection as js dict).
> (I use it to pass configuration to tsv papa parser)
>
> a+
> Vicnet
> Le lundi 28 avril 2014 12:08:57 UTC+2, Hannes a écrit :
>>
>>
>> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>>
>>
>> Link corrected.
>>
>> On 4/28/14, H. Hirzel <[hidden email] <javascript:>> wrote:
>> > Hello
>> >
>> > I put a question here
>> >
>> >
>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>
>> >
>> > Answers to the ML are welcome as well of course.
>> >
>> > Regards and best wishes for a happy Amber coding week
>> >
>> > Hannes
>> >
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Hannes Hirzel
Done.

HH

On 4/28/14, H. Hirzel <[hidden email]> wrote:

> Vicnet
>
> Thank you for the feedback. That is great! The wiki is yours as well.
> So you might as well just go ahead and do it
>
> Can you give some more information what you are doing with the 'papa
> parser'?
>
> --Hannes
>
> On 4/28/14, Vicnet <[hidden email]> wrote:
>> Hello,
>>
>> Wath do you think to add a link on wiki page on javascrit constructor
>> https://github.com/amber-smalltalk/amber/wiki/Call-javascript-constructors-with-arguments
>> into general wiki page on converting js to st
>> https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>>
>> And also add the page link on literral notation
>> https://github.com/amber-smalltalk/amber/wiki/Literal-notation
>> on the same page.
>> because theses notations could be used directly in js code
>> (hashedcollection as js dict).
>> (I use it to pass configuration to tsv papa parser)
>>
>> a+
>> Vicnet
>> Le lundi 28 avril 2014 12:08:57 UTC+2, Hannes a écrit :
>>>
>>>
>>> http://stackoverflow.com/questions/23337995/how-do-i-translate-javascript-constructors-to-amber-smalltalk
>>>
>>>
>>> Link corrected.
>>>
>>> On 4/28/14, H. Hirzel <[hidden email] <javascript:>> wrote:
>>> > Hello
>>> >
>>> > I put a question here
>>> >
>>> >
>>> http://stackoverflow.com/questions/23337995/how-do-i-translated-javascript-constructors-to-amber-smalltalk
>>>
>>> >
>>> > Answers to the ML are welcome as well of course.
>>> >
>>> > Regards and best wishes for a happy Amber coding week
>>> >
>>> > Hannes
>>> >
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "amber-lang" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [hidden email].
>> For more options, visit https://groups.google.com/d/optout.
>>
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I translate Javascript constructors to Amber Smalltalk code?

Vicnet-2
In reply to this post by Hannes Hirzel
Hello,

Le lundi 28 avril 2014 22:20:29 UTC+2, Hannes a écrit :
Can you give some more information what you are doing with the 'papa parser'?

Just a data importer for a (little) specific app to manage volonteers in a game festival.
https://github.com/vicnet/benevoles

Thanks for wiki updates.

a+
Vicnet

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.