Sha256: e52f93dfef72355b23422f7c7d625d72fbf408da48222786e1a485d687c6e3cb

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

# Sexps gotten from translating Greeter#greet and Greeter#greet_changed
# from example_classes.rb

# before translation (formatted manually)
s(:defn, :greet,
  s(:scope,
    s(:block, s(:args),
      s(:if, s(:ivar, :@hello),
        s(:str, "Hello World!"),
        s(:str, "Goodbye")
      )
    )
  )
)

# after translation
s(:defn, :greet_changed,
  s(:scope,
    s(:block, s(:args),
      s(:fcall, :my_if,
        s(:array,
          s(:iter,
            s(:fcall, :lambda), nil, s(:ivar, :@hello)
          ),
          s(:iter,
            s(:fcall, :lambda), nil, s(:str, "Hello World!")
          ),
          s(:iter,
            s(:fcall, :lambda), nil, s(:str, "Goodbye")
          )
        )
      )
    )
  )
)

# OK, so here's the rule that I'm inferring from this example:

# We start with 
s(:if, condition, then_do, else_do)
# Where condition, then_do, and else_do are "variables" containing
# arbitrary sexps

# Our rewriter should turn this into
s(:fcall, :my_if,
  s(:array,
    s(:iter,
      s(:fcall, :lambda), nil, ~condition
    ),
    s(:iter,
      s(:fcall, :lambda), nil, ~then_do
    ),
    s(:iter,
      s(:fcall, :lambda), nil, ~else_do
    )
  )
)
# Where ~condition is the expansion of condition, inserting the
# sexp it points to, and similar for then_do and else_do

# Question: What does the :iter part mean exactly?
# Also, how exactly does the call to lambda map to the sexp?
# It takes a block, so that complicates the syntax.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
virtual_keywords-0.3.1 lib/sexps/sexps_greet.rb
virtual_keywords-0.3.0 lib/sexps/sexps_greet.rb
virtual_keywords-0.1.0 lib/sexps/sexps_greet.txt
virtual_keywords-0.0.0 lib/sexps/sexps_greet.txt