Permalink
Browse files

Tweaks for SPLASH/StrangeLoop.

  • Loading branch information...
birchb1024 committed Aug 5, 2014
1 parent c66fadc commit be8a19b1453be510b386e02c91385388ab2aa52c
Showing with 66 additions and 38 deletions.
  1. +15 −5 examples/length.g
  2. +41 −29 examples/people.g
  3. +10 −4 sandpit/boston.g
@@ -8,24 +8,32 @@ class Inches(Bignum)
def .toMeters()
* .self 0.0254
# syntactic sugar
def inches()
tag Inches .self
# create some data
define a-foot
tag Inches 12
12(inches)
assert
equal?
a-foot (.toMeters)
0.3048
# Now add a super-class and another Unit...
class Length()
def .toMeters()
raise "Oops - you invoked an abstract class."
raise "Oops - you called an abstract class."
class Inches(Length)
def .toMeters()
tag Meters (* .self 0.0254)
class Meters(Length)
def .toMeters() .self
def meter()
tag Meters .self
Length
def .add(other)
@@ -34,10 +42,12 @@ Length
other (.toMeters)
define a-meter
tag Meters 1
# create some data
define a-meter
1(meter)
define a-foot (tag Inches 12)
define a-foot
12(inches)
assert
equal?
@@ -1,8 +1,10 @@
## Copyright 2008 Peter William Birch <birchb@genyis.org>
## Copyright 2014 Peter William Birch <birchb@genyis.org>
##
## This software may be used and distributed according to the terms
## of the Genyris License, in the file "LICENSE", incorporated herein by reference.
##
# Uses Friend Of A Friend class names.
@prefix foaf 'http://xmlns.com/foaf/0.1/'
include "lib/classify.g"
@@ -12,55 +14,65 @@ def between (low it high)
< it high
> it low
define neil
dict
.foaf:name = "Neil Wheedon Watkins Pye"
.foaf:age = 49
.bong = true
define vyvyan
dict
.foaf:name = "Vyvyan"
.foaf:age = 49
class foaf:name
define rick
dict
.name = (tag foaf:name "Rick") # not legal in RDF
class foaf:Person ()
def .valid? (obj)
# simple type inference from foaf:age to foaf:Person
# Any object with a foaf:age is a foaf:Person
def .valid? (obj)
obj
bound? ^.foaf:age
class Kid (foaf:Person)
def .valid? (obj)
obj
< .foaf:age 15
# Kids are younger than 15
def .valid? (obj)
obj
< .foaf:age 15
class Senior (foaf:Person)
def .valid? (obj)
obj
between 60 .foaf:age 120
# Older than 60 makes a Senior
def .valid? (obj)
obj
between 60 .foaf:age 120
class Boomer (foaf:Person)
def .valid? (obj)
obj
between 45 .foaf:age 60
# Baby boomers
def .valid? (obj)
obj
between 45 .foaf:age 60
class Hippie (Boomer)
def .valid? (obj)
obj
bound? ^.bong
# A baby boomer who owns a bong
def .valid? (obj)
obj
bound? ^.bong
# Let's create some data and assign to variables...
define neil
dict
.foaf:name = "Neil Wheedon Watkins Pye"
.foaf:age = 49
.bong = true
define vyvyan
dict
.foaf:name = "Vyvyan"
.foaf:age = 49
define rick
dict
.name = (tag foaf:name "Rick") # not legal in RDF
# Classify the data..
classify foaf:Person neil
classify foaf:Person vyvyan
classify foaf:Person rick
# What classes did we get?
assert
and
is-instance? neil Hippie
is-instance? vyvyan Boomer
not
is-instance? rick foaf:Person
is-instance? rick!name foaf:name
@@ -10,14 +10,20 @@ var boston # variable declaration
# Library from culturevulture.org
@prefix c "http://culturevulture.org/styles#"
class c:EastCoast
class c:EastCoast()
tag c:EastCoast boston # marks the object with a class
# Library from politics.com
@prefix pl "http://politics.com/leanings#"
class pl:Democrat
class pl:Democrat()
tag pl:Democrat boston # marks the object with an additional class
is-instance? boston pl:Democrat
is-instance? boston c:EastCoast
assert
and
is-instance? boston pl:Democrat
is-instance? boston c:EastCoast
print boston
for c in (boston.classes)
print c!name

0 comments on commit be8a19b

Please sign in to comment.