Skip to content

Spry JavaScript REPL

On this page we have the Spry interpreter compiled, together with 10 extra VM modules (core, debug, extend, math, OO, string, modules, reflect, block and browser) and minified to about 157kb ugly js. You can find this in github.

You can enter code and eval below, output is appended below the code area. Code is evaluated in the same interpreter so assignments are kept between evaluations.

Here are just some examples:

# Spry is homoiconic
code = [3 + 4]
code at: 0 put: 8
do code
# Let's add a method to:do: that works as in Smalltalk.
# Methods take the first argument, the "receiver", from the left
# and binds it to "self". Note second assignment is a "reassignment"
# so that we for sure assign the outer n and not a new local n.
# This already exists implemented as a native.
to:do: = method [:to :block
  n = self
  [n <= to] whileTrue: [
    do block n
    n := (n + 1)]]

# Then we can loop in Smalltalk style echoing 1 to 5!
1 to: 5 do: [echo :x]
# We can similarly implement select: from Smalltalk.
# This already exists implemented as a native, but anyway.
select: = method [:pred
  result = clone []
  self reset
  [self end?] whileFalse: [
    n = (self next)
    do pred n then: [result add: n]]
  ^result]

# Then use it to produce [3 4]
[1 2 3 4] select: [:x > 2]

Enter Spry code: