Hello,
Would it be possible to use existing built in compiler to translate a string like: '[:x :y | x + y]' into string containing source for anonymous javascript function? Davorin Ruševljan http://www.cloud208.com/ |
Am 17.12.2012 um 10:40 schrieb Davorin Ruševljan <[hidden email]>: > Hello, > > Would it be possible to use existing built in compiler to translate a string like: > > '[:x :y | x + y]' > > into string containing source for anonymous javascript function? > You mean something like that? (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource ? Norbert P.S.: Btw. Hi, first post to this list :) |
On Monday, December 17, 2012 10:57:46 AM UTC+1, Norbert Hartl wrote:
yes, though my Amber (one started from amber-lang home page) does not understand evaluateExpression :) I am tinkering a bit with Amber + CouchDB, and thought that maybe it would be possible to provide CouchDB map and reduce functions as Smalltalk blocks and compile them to javascript by Amber before putting them into the database views. P.S.: Btw. Hi, first post to this list :) thanks! (I did post quite some time before, but it was such a long time ago, that we can count this a s first again!) |
On 12/17/2012 11:22 AM, Davorin Ruševljan wrote:
> On Monday, December 17, 2012 10:57:46 AM UTC+1, Norbert Hartl wrote: > > > You mean something like that? > > (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource > > > yes, though my Amber (one started from amber-lang home page) does not > understand evaluateExpression :) > > I am tinkering a bit with Amber + CouchDB, and thought that maybe it > would be possible to provide CouchDB map and reduce functions as > Smalltalk blocks and compile them to javascript by Amber before putting > them into the database views. Just as a curiosity - I did implement a "view server" in Pharo (or perhaps it was Squeak) for CouchDB a while back so that you could use Squeak for map/reduce functions. Worked fine, but of course, the map reduce functions are normally so small I really don't see the big point. And since then I have also moved over to Riak for my "NoSQL fix". :) regards, Göran |
On Monday, December 17, 2012 12:22:40 PM UTC+1, Göran Krampe wrote:
yes, using smalltalk view server is an option, but it requires smalltalk to be installed on the machine hosting the CouchDB. My current question came from different angle - trying to using Amber to write CouchApps. In CouchApp the application code itself is served from the CouchDB server - which has among other things consequence that application can query database without "same origin" workarounds. And they can get replicated. So my imagined AmberCouchApp would be developed in Amber IDE, but instead of being saved to local fs it would get stored directly in CouchDB. In such scenario when CouchApp is pushed to the server from Amber, I thought that it might be nice to write view functions as smalltalk blocks and push them together with smalltalk presentation code. It is not a biggie - but it would probably be nice. There is already somehow similar idea developed with storing amber source code to the online database (but not couchdb), but I do not have link at hand. Thanks for the input! (though I still welcome a good tip how to get javascript source for the block) Davorin |
In reply to this post by drush66
That's because on amber-lang.net the old compiler is used. You can do instead: (Compiler new loadExpression: '[1+2]') compiledSource Nico Davorin Ruševljan <[hidden email]> writes: > On Monday, December 17, 2012 10:57:46 AM UTC+1, Norbert Hartl wrote: >> >> >> You mean something like that? >> >> (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource >> >> > yes, though my Amber (one started from amber-lang home page) does not > understand evaluateExpression :) > > I am tinkering a bit with Amber + CouchDB, and thought that maybe it would > be possible to provide CouchDB map and reduce functions as Smalltalk blocks > and compile them to javascript by Amber before putting them into the > database views. > > P.S.: Btw. Hi, first post to this list :) > > > thanks! (I did post quite some time before, but it was such a long time > ago, that we can count this a s first again!) > -- Nicolas Petton http://nicolas-petton.fr |
In reply to this post by NorbertHartl
Welcome to Amber Norbert :) Norbert Hartl <[hidden email]> writes: > Am 17.12.2012 um 10:40 schrieb Davorin Ruševljan <[hidden email]>: > >> Hello, >> >> Would it be possible to use existing built in compiler to translate a string like: >> >> '[:x :y | x + y]' >> >> into string containing source for anonymous javascript function? >> > You mean something like that? > > (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource > > ? > > Norbert > > P.S.: Btw. Hi, first post to this list :) Nicolas Petton http://nicolas-petton.fr |
In reply to this post by drush66
On 12/17/2012 11:22 AM, Davorin Ruševljan wrote:
> On Monday, December 17, 2012 10:57:46 AM UTC+1, Norbert Hartl wrote: > > > You mean something like that? > > (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource > > > yes, though my Amber (one started from amber-lang home page) does not > understand evaluateExpression :) > > I am tinkering a bit with Amber + CouchDB, and thought that maybe it > would be possible to provide CouchDB map and reduce functions as > Smalltalk blocks and compile them to javascript by Amber before putting > them into the database views. Just as a curiosity - I did implement a "view server" in Pharo (or perhaps it was Squeak) for CouchDB a while back so that you could use Squeak for map/reduce functions. Worked fine, but of course, the map reduce functions are normally so small I really don't see the big point. And since then I have also moved over to Riak for my "NoSQL fix". :) regards, Göran |
In reply to this post by Nicolas Petton
On Monday, December 17, 2012 1:00:29 PM UTC+1, nicolas petton wrote:
Thanks, 1) can this code be used as standalone, or it needs some other supporting code/library to work? 2) how does one invoke in Amber global function? 3) can I somehow provide it with name space to use? for instance resulting code I would like end up with javascript function that looks like: function(doc) { emit(doc.user, doc.name); } Hmm.. more I look at it, it seems like a too big stretch. |
I'm answering inside your email.
Davorin Ruševljan <[hidden email]> writes: > On Monday, December 17, 2012 1:00:29 PM UTC+1, nicolas petton wrote: >> >> >> That's because on amber-lang.net the old compiler is used. You can do >> instead: >> >> (Compiler new loadExpression: '[1+2]') compiledSource >> >> > Thanks, > > 1) can this code be used as standalone, or it needs some other supporting > code/library to work? It is very likely that would will need amber libraries to run your function, as you will probably call amber methods. > 2) how does one invoke in Amber global function? I don't understand this question :) > 3) can I somehow provide it with name space to use? for instance resulting > code I would like end up with javascript function that looks like: > > function(doc) { > emit(doc.user, doc.name); > } Not really. The compiled code *is* Amber compiled code to JS, not JS that's supposed to be run standalone. Cheers, Nico |
On Monday, December 17, 2012 2:15:59 PM UTC+1, nicolas petton wrote:
> 2) how does one invoke in Amber global function? I wanted to ask, how can I invoke javascript function from amber smalltalk code. I. e. what code I need to write in amber smalltalk so that resulting javascript code would be for instance: emit("something); But the rest of your answers rendered this question as not so important. > 3) can I somehow provide it with name space to use? for instance resulting Ok, so it is not a good idea, I will stick with only javascript for view functions. Thanks! Davorin |
What do you want to do? If what you need is to call javascript libraries from Amber, there is a way to do it. JavaScript objects can be used from Amber seemlessly (it will use a proxy internally). Here's an example with jQuery: (window jQuery: 'body') css: 'background' put: 'red' it is explained in the doc here: http://amber-lang.net/documentation.html#JSObjectProxy and on the github wiki here: https://github.com/NicolasPetton/amber/wiki/From-smalltalk-to-javascript-and-back Cheers, Nico Davorin Ruševljan <[hidden email]> writes: > On Monday, December 17, 2012 2:15:59 PM UTC+1, nicolas petton wrote: >> >> > 2) how does one invoke in Amber global function? >> >> I don't understand this question :) >> > > I wanted to ask, how can I invoke javascript function from amber smalltalk > code. I. e. what code I need to write in amber smalltalk so that resulting > javascript code would be for instance: > > emit("something); > > But the rest of your answers rendered this question as not so important. > >> 3) can I somehow provide it with name space to use? for instance >> resulting >> > code I would like end up with javascript function that looks like: >> > >> > function(doc) { >> > emit(doc.user, doc.name); >> > } >> >> Not really. The compiled code *is* Amber compiled code to JS, not JS >> that's supposed to be run standalone. >> >> > Ok, so it is not a good idea, I will stick with only javascript for view > functions. > > Thanks! > > Davorin > -- Nicolas Petton http://nicolas-petton.fr |
On Monday, December 17, 2012 2:41:59 PM UTC+1, nicolas petton wrote:
Well, those examples have explicit receiver (like window in example above). What I was asking about was direct invocation of function without explicit receiver, like invocation of emit() in example below: function(doc) { .... emit(1); .... } What would I need to put as a receiver in equivalent smalltalk code instead of xyz? xyz emit:1 Though, since using Amber to generate standalone javascript functions from a smalltalk block is not an easily workable idea, the whole question is somehow less important. Davorin |
Am 17.12.2012 um 15:02 schrieb Davorin Ruševljan <[hidden email]>: Well, those examples have explicit receiver (like window in example above). What I was asking about was direct invocation of function without explicit receiver, like invocation of emit() in example below: In this case it is probably best to use javascript direct. Javascript can be put into <> to be executed. So a < emit(1) > should work. Even returned values can then be assigned to smalltalk vars etc. Norbert
|
On Monday, December 17, 2012 3:07:14 PM UTC+1, Norbert Hartl wrote:
thanks! Davorin |
In reply to this post by NorbertHartl
Norbert Hartl wrote: > > Am 17.12.2012 um 15:02 schrieb Davorin Ruševljan > <[hidden email] <mailto:[hidden email]>>: > >> Well, those examples have explicit receiver (like window in example >> above). What I was asking about was direct invocation of function >> without explicit receiver, like invocation of emit() in example below: >> function(doc) { >> .... >> emit(1); >> .... >> } >> >> What would I need to put as a receiver in equivalent smalltalk code >> instead of xyz? >> >> xyz emit:1 > > In this case it is probably best to use javascript direct. Javascript > can be put into <> to be executed. So a > > < emit(1) > > > should work. Even returned values can then be assigned to smalltalk vars > etc. "emit value: 1" should work as well, but it is not direct call (gone through smalltalk machinery where #value: eventually calls it, so is slower; but more smalltalkish). > Norbert Herby |
In reply to this post by drush66
On 12/17/2012 11:22 AM, Davorin Ruševljan wrote:
> On Monday, December 17, 2012 10:57:46 AM UTC+1, Norbert Hartl wrote: > > > You mean something like that? > > (Compiler new evaluateExpression: '[:x :y | x + y]') compiledSource > > > yes, though my Amber (one started from amber-lang home page) does not > understand evaluateExpression :) > > I am tinkering a bit with Amber + CouchDB, and thought that maybe it > would be possible to provide CouchDB map and reduce functions as > Smalltalk blocks and compile them to javascript by Amber before putting > them into the database views. Just as a curiosity - I did implement a "view server" in Pharo (or perhaps it was Squeak) for CouchDB a while back so that you could use Squeak for map/reduce functions. Worked fine, but of course, the map reduce functions are normally so small I really don't see the big point. And since then I have also moved over to Riak for my "NoSQL fix". :) regards, Göran |
Free forum by Nabble | Edit this page |