[gambit-list] How to express javascript prototypes

ben yakawp ben.lists at yakawp.com
Mon Dec 21 09:29:21 EST 2015


and another thing I'd like to point out with this example: I find really
difficult to debug the produced code. This is probably because GambitJS
doesn't simply transpile the source code but uses the target language as
a host for its virtual machine which has its own semantics.

I tried to use Marc Feeleys code to mimic OO style in scheme for
prototypes:

; OO
(define (new constructor . args)
  (let ((obj (create-object constructor args)))
    (lambda (method . args)
      (call-method obj method args))))

; Prototypes
(define (proto constructor . args)
    (lambda (method . args)
      (call-method constructor method args)))

(define console (proto 'console))
(console log:)

Error:
/out.js:935
    g_r1 = g_host2scm(g_r1[g_r2.toString()].call(g_r1));
    TypeError: Cannot call method 'call' of undefined

Question:
- I would like to find out the value of "console". But what makes more
sense: Debugging the value "console" in the c platform of the js
platform? 
- How can you debug the javascript code? Alone the line
          "g_r1 = g_host2scm(g_r1[g_r2.toString()].call(g_r1)); "
is somehow mindblowing to me. You seem to reach out to scheme again from
the generated code. I cannot follow this...


On Mon, Dec 21, 2015, at 01:39 PM, ben yakawp wrote:
> hi
> I have a the following problem: Initially I was looking for a simple way
> to write code on several platforms with scheme as the "reference
> platform". This is more difficult then I thought because most of the
> target languages have libraries that are build with an OO model. That
> leaks into the platform neutral source code, so that you write scheme
> but with OO in mind. Now I see a next problem, that of Javascript making
> extensive use of "prototyping", again a specific model that has to be
> ported to other languages.
> 
> So my question is, how would you express prototyping in a platform
> neutral way, so that you can (hypothecally) use the source code also for
> target languages that don't support prototyping.
> 
> Hopefully I don't make this much more complicated than it is.
> Ben
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list


More information about the Gambit-list mailing list