class Obj
end
# Value operated by Scheme
alias Val = Nil | Obj | Bool | String | Int32 | Float64 | BigInt
to define Cons Cell of Scheme: # Cons cell
class Cell < Obj
include Enumerable(Val)
getter car : Val # Head part of the cell
property cdr : Val # Tail part of the cell
def initialize(@car : Val, @cdr : Val)
end
...
end # Cell
Note that you see generics, Enumerable(Val), and constructor arguments with '@' in the excerpt above.
Agreed. And if you prefer methods to functions, you can define methods on such a function type! In my LINQ in Go (https://github.com/nukata/linq-in-go), I define a higher order function type:
and several methods on it, for example,
Naturally, if you need another type parameter for a method, you must define it as a function. For example,
Now, with the function which converts a slice to an Enumerator,
you can write the following: