Enhanced Amber REPL

96 views
Skip to first unread message

Markus Kahl

unread,
Jun 23, 2013, 2:44:59 PM6/23/13
to amber...@googlegroups.com
Hey,

I've enhanced the Amber REPL a little because I wanted to play around a bit (with access to node.js) and it was missing a couple of things I'm used to.
Dunno how commonly used the REPL is, but do you think it'd make sense to create a pull request?
This way perhaps other people could get a more useful REPL, too.
Are there any coding standards I'd need to pay attention to?
My Smalltalk style is quite possibly horrible.

A little picture demonstrating some of the new REPL features

Additionally to the features shown in the screenshot (mainly variables) I've also implemented Ctrl+L to clear the screen.

~ Markus


Manfred Kröhnert

unread,
Jun 24, 2013, 4:27:39 AM6/24/13
to amber...@googlegroups.com

Hello Markus,

don't hesitate to open a pull-request.
If there is something which needs some tweaking we will discuss it there.
It is also great if you write a short summary of the changes there so we don't have to go through the commits to extract that information :-)

And for the coding style there is a wiki page mentioning the most important things.

Regarding ':q to quit'.
Didn't the REPL already understand the 'quit' message?

Best regards,
Manfred

--
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 amber-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Markus Kahl

unread,
Jun 24, 2013, 6:01:50 AM6/24/13
to amber...@googlegroups.com, mkroeh...@googlemail.com
Hey,

alright thanks, I've just created one.
The repl didn't understand 'quit' as far as I know. Also no sign of anything like it in the code.

~ Markus

Nicolas Petton

unread,
Jun 24, 2013, 7:11:43 AM6/24/13
to amber...@googlegroups.com, mkroeh...@googlemail.com
That's really cool!

About coding conventions, please read this page https://github.com/amber-smalltalk/amber/wiki/Coding-conventions
I can be quite annoying with this, but I think it is important to try stick to it as much as possible :)

Keep up the great work!
Nico

Manfred Kröhnert

unread,
Jun 24, 2013, 7:31:42 AM6/24/13
to amber...@googlegroups.com
Hi Markus,

On Mon, Jun 24, 2013 at 12:01 PM, Markus Kahl <mach...@gmail.com> wrote:
Hey,

alright thanks, I've just created one.

Great!
 
The repl didn't understand 'quit' as far as I know. Also no sign of anything like it in the code.

Okay, then I just remembered incorrectly.
 
~ Markus

Keep going :-)
Manfred

H. Hirzel

unread,
Sep 7, 2013, 1:51:05 AM9/7/13
to amber...@googlegroups.com
Hello Markus

With the current amber the q command in the REPL does not work properly.

I start the REPL loop in MSWindows with

C:\Users\User\Documents\projects>vendor\amber\bin\amber repl

C:\Users\User\Documents\projects>vendor\amber\bin\amber repl
Welcome to Amber version 0.12.0-pre (NodeJS 0.10.17).
Type :q to exit.

amber >> 1 + 1
res1: Number = 2

amber >> q
a block (in nil)
Repl >> processLine:
Repl >> assignNewVariable:do:
Repl >> parseAssignment:do:
BlockClosure >> value:value:
a block (in BlockClosure >> value:value:)
Repl >> eval:on:
Repl >> try:catch:
BlockClosure >> value
a block (in BlockClosure >> value)
Compiler >> evaluateExpression:on:
Compiler >> compileExpression:on:
Compiler >> compileNode:
InliningCodeGenerator >> compileNode:
SemanticAnalyzer >> visit:
MethodNode >> accept:
SemanticAnalyzer >> visitMethodNode:
SemanticAnalyzer >> visitMethodNode:
SemanticAnalyzer >> visitNode:
SemanticAnalyzer >> visitAll:
Array >> collect:
BlockClosure >> value:
a block (in BlockClosure >> value:)
SemanticAnalyzer >> visit:
SequenceNode >> accept:
SemanticAnalyzer >> visitSequenceNode:
SemanticAnalyzer >> visitSequenceNode:
SemanticAnalyzer >> visitNode:
SemanticAnalyzer >> visitAll:
Array >> collect:
BlockClosure >> value:
a block (in BlockClosure >> value:)
.......

Regards
Hannes
>>>> <https://lh3.googleusercontent.com/-lZCW70DDb4I/UcdBSVbifVI/AAAAAAAAAFA/gNgFWmL8c44/s1600/amber-repl.png>
>>>>
>>>> A little picture demonstrating some of the new REPL features
>>>>
>>>> Additionally to the features shown in the screenshot (mainly variables)
>>>> I've also implemented Ctrl+L to clear the screen.
>>>>
>>>> ~ Markus
>>>>
>>>>
>

Thomas Rake

unread,
Sep 7, 2013, 8:54:15 PM9/7/13
to amber...@googlegroups.com
Hello Hanes,

The REPL quit command is  ':q' which works on my Window machine based on the current master. Typing just q results in a Amber trace for the undefined symbol q.

Markus Kahl

unread,
Sep 8, 2013, 7:21:27 PM9/8/13
to amber...@googlegroups.com
Exatly what Thomas said. Perhaps we should have an appropriate error message (var not found or similar) instead of the trace when you just type q, though.

H. Hirzel

unread,
Sep 9, 2013, 12:14:24 AM9/9/13
to amber...@googlegroups.com
Yes, something like 'var not found' or 'q is undefined'. For any
undefined variable there are these trace messages.

And: How do I load and execute a script?

--Hannes

Manfred Kröhnert

unread,
Sep 9, 2013, 1:21:55 PM9/9/13
to amber...@googlegroups.com
Yes, printing an error message instead of showing a stacktrace sounds like a good addition.

As of now it is not possible to load and execute external scripts.
However, it should not be too hard to support this since one would have to do the same steps amberc does without writing the file back out again.
But Writing Packages to disk sounds like a nice addition, too.

Best,
Manfred




Manfred Kröhnert

unread,
Sep 9, 2013, 1:32:04 PM9/9/13
to amber...@googlegroups.com

Sebastian Heidbrink

unread,
Oct 2, 2013, 10:40:15 PM10/2/13
to amber...@googlegroups.com
Hi!

I have one problem here.

I want to map Json to my data model.
Unfortunately one of the fields in JSON can either by a single object,
or an array of objects.
Is there a way to find out if a JSProxyObject is a collection, array or
single object?

Unfortunately JSProxyObject does not understand asArray....

How do you mapp JSON to your Amber data model?

I tried this with the most recent Amber sources from GitHub master branch.

Thanks!
Sebastian

Herby Vojčík

unread,
Oct 3, 2013, 8:31:20 AM10/3/13
to amber...@googlegroups.com
What's the problem with `JSON parse:` and using the result directly.

An array is always a JS Array instance, that is, Amber Array instance. No need to take care of JSObjectProxy.

Herby

Sebastian Heidbrink

unread,
Oct 3, 2013, 10:04:46 AM10/3/13
to amber...@googlegroups.com
Hi Herby,

you are right that is the case if a certain field or property within the
JSON is defined as array or object.
But the JSON I got states that a certain property can be a single object
or an array.
So if I want to handle this in my data model as an array in general then
I am in trouble right now.
I need to take the parsed JSON and the specific property and transform
the contents into my smalltalk objects.

like

jsonPropertyArrayOrObject do: [:each | myAmberSmalltalkArray add:
(myDataModelClass from: each)].

An object does not understand "do:" and a jsonPropertyArrayOrObject does
not understand "isArray" since it can alos be a JSObjectProxy...

Does this make sense?

Sebastian

Herby Vojčík

unread,
Oct 3, 2013, 10:21:18 AM10/3/13
to amber...@googlegroups.com


Sebastian Heidbrink wrote:
> Hi Herby,
>
> you are right that is the case if a certain field or property within
> the JSON is defined as array or object.
> But the JSON I got states that a certain property can be a single
> object or an array.
> So if I want to handle this in my data model as an array in general
> then I am in trouble right now.
> I need to take the parsed JSON and the specific property and transform
> the contents into my smalltalk objects.
>
> like
>
> jsonPropertyArrayOrObject do: [:each | myAmberSmalltalkArray add:
> (myDataModelClass from: each)].
>
> An object does not understand "do:" and a jsonPropertyArrayOrObject
> does not understand "isArray" since it can alos be a JSObjectProxy...
>
> Does this make sense?

I see. Well, yes, there is nothing like `isProxy` or `asObject` (`yourself` could play the role of asObject, it already kind-of does it for JS primitives; but for proxy, this is all much more complicated - for example `copy` could crea
te Amber-usable copy of a wrapped object, but again, adding more API to JSObjectProxy may backfire when original object has such method as well).

> Sebastian

Herby

Sebastian Heidbrink

unread,
Oct 3, 2013, 10:25:48 AM10/3/13
to amber...@googlegroups.com
Herby,

and there is no other way to parse Json right now? I mean something like
NeoJSON or STON?

Some Parser where I could define that this property must result in an Array?

Sebastian

Herby Vojčík

unread,
Oct 3, 2013, 10:31:15 AM10/3/13
to amber...@googlegroups.com


Sebastian Heidbrink wrote:
> Herby,
>
> and there is no other way to parse Json right now? I mean something like
> NeoJSON or STON?
>
> Some Parser where I could define that this property must result in an
> Array?

It is silly to want other parser in a platform where JSON.parse is
built-in, so I would say there is none and there will be none.

Add your own asObject/deproxy/whatever as extension method to Object and
JSObjectProxy, you're in Smalltalk after all.

> Sebastian

Herby

Herby Vojčík

unread,
Oct 3, 2013, 10:33:22 AM10/3/13
to amber...@googlegroups.com
> Add your own asObject/deproxy/whatever as extension method to Object
> and JSObjectProxy, you're in Smalltalk after all.

Or 'isArray ^false' when we're at it :-)

>> Sebastian
>
> Herby
>

Sebastian Heidbrink

unread,
Oct 3, 2013, 10:40:04 AM10/3/13
to amber...@googlegroups.com
Thank you Herby!

Well, I am on your side.
I will solve try to solve this problem temporarily this way, but maybe I
can even ask for a general change of this delivered JSON.

This reminds me of a MayBe that I once needed to implement as a sub
class of boolean.
I had a typed data source and they managed to define a boolean that
could be "empty".... now represent that in Smalltalk "yes", "no", ???
"maybe" :-D

Well at least I didn't oversea anything in Amber regarding my
JsProxyObject kind of problem.

Sebastian
Reply all
Reply to author
Forward
0 new messages