Sha256: 57fdb342bdcfbc6bd1eb4e3a6a9534f821f79cf39091d77511a4b565d87c03e3

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# Structure of a while
# So the first element is the condition, and the second is the body, wrapped
# in a :block (TODO and then a "true", what is it for?)
s(:defn, :while_count_to_value,
  s(:scope,
    s(:block, s(:args),
      s(:while,
        # The condition
        s(:call, s(:ivar, :@i), :<,
          s(:array, s(:vcall, :value))
        ),
        # End condition
        # The body
        s(:block,
          s(:call, s(:ivar, :@counts), :<<,
            s(:array, s(:ivar, :@i))
          ),
          s(:iasgn, :@i,
            s(:call, s(:ivar, :@i), :+,
              s(:array, s(:lit, 1))
            )
          )
        ),
        # End body
        true
      )
    )
  )
)

# After
s(:defn, :while_result,
  s(:scope,
    s(:block, s(:args),
      s(:fcall, :my_while,
        s(:array,
          s(:iter,
            s(:fcall, :lambda), nil,
            # The condition
            s(:call, s(:ivar, :@i), :<,
              s(:array, s(:vcall, :value))
            )
            # End condition
          ),
          s(:iter,
            s(:fcall, :lambda), nil,
            # The body
            s(:block,
              s(:call, s(:ivar, :@counts), :<<,
                s(:array, s(:ivar, :@i))
              ),
              s(:iasgn, :@i,
                s(:call, s(:ivar, :@i), :+,
                  s(:array, s(:lit, 1))
                )
              )
            )
            # End body
          )
        )
      )
    )
  )
)

Version data entries

3 entries across 3 versions & 1 rubygems

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