Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby is verbose, compared to Symta

Name: Anonymous 2014-12-21 18:14

Symta:
type person{Name Age} name/Name age/Age
person.`<` X = $age < X.age
person.as_text = "{$name} ({$age})"

Group = [person{'Bob' 33}, person{'Chris' 16}, person{'Ash' 16}]

say Group.sort.flip


Ruby:
class Person
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age
end
def <=>(person) # the comparison operator for sorting
age <=> person.age
end
def to_s
"#{name} (#{age})"
end
end

group = [
Person.new("Bob", 33),
Person.new("Chris", 16),
Person.new("Ash", 23)
]

puts group.sort.reverse

Name: Anonymous 2014-12-24 22:11

>>27
Message doInContext, see http://iolanguage.org/scm/io/docs/reference/Core/Core/Message/index.html

Instead of auto-quoting, which we've already seen, I went with varible interpolation from the caller:

Person := Object clone do(
name ::= nil
age ::= nil
asString := method("#{name} (#{age})" interpolate)
curlyBrackets := method(a,b,
self clone setName(a) setAge(b))
squareBrackets := method(
call message arguments map(doInContext(Person, call sender)))

Io> a := "Jim"; b := 23
Io> Person [ {"Frank", 45}, {a, b} ]
==> list(Frank (45), Jim (23))


It's just a constructor for the same thing... nothing changes about the result. >>19-san's sorting still works the same:

Io> group := Person [{"Bob", 33}, {"Chris", 16}, {"Ash", 23}]
Io> group sortInPlace(age) reverse println
==> list(Bob (33), Ash (23), Chris (16))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List