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 9:02

>>20
curlyBrackets and squareBrackets are left undefined for DSL purposes. But the better thing to do is something like this:

ListBuilder := Object clone do(
squareBrackets := method(call evalArgs))
List appendProto(ListBuilder)

Person := Object clone do(
name ::= nil
age ::= nil
curlyBrackets := method(
self clone setName(call argAt(0)) \
setAge(call argAt(1))))

p := Person
group := List [ p {Bob, 33}, p {Chris, 16}, p {Ash, 23} ]


This way the constructor/DSLs are scoped to the appropriate type. Person could have used squareBrackets as the constructor and it wouldn't interfere with List. You could also have something like this:

Person [ {Bob, 33}, {Chris, 16}, {Ash, 23} ]

without needing to define curlyBrackets on Object by evaluating the arguments in a different context (like Person, for example.)

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