Created
April 24, 2012 02:15
-
-
Save robotlolita/2475522 to your computer and use it in GitHub Desktop.
school -- COOL meets Smalltalk and Scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Basic features | |
-- * Classical OO, objects for everything | |
-- * Dynamically typed | |
-- * Keyword parameters | |
-- * First class lambdas | |
-- * Single inheritance, Single dispatch | |
-- * Traits (?) | |
-- * Most control flow as in-language constructs | |
-- Special forms | |
-- | |
-- * Class definition | |
-- * Method definition | |
-- * Field definition | |
-- * Object instantiation | |
-- * Assignments | |
-- * String, Bool, Number and Symbol literals | |
-- * Lambda | |
class Bool { | |
then: consequent else: otherwise => new AbstractException. | |
not => self then: { new True } | |
else: { new False }. | |
} | |
class True inherits Bool { | |
then: consequent else: otherwise => call consequent. | |
} | |
class False inherits Bool { | |
then: consequent else: otherwise => call otherwise. | |
} | |
class While { | |
init: predicate do: block => (call predicate) then: { call block. | |
new While predicate do: block }. | |
} | |
class Factorial { | |
init: n => (n = 0) then: { 1 } | |
else: { new Factorial ((n - 1) * n) }. | |
} | |
class Number { | |
op <- new native::Operator. | |
-- Operators --------------------------------------------------------- | |
+: b => op.sum self b. | |
-: b => op.subtract self b. | |
/: b => op.divide self b. | |
*: b => op.multiply self b. | |
} | |
(new Number 1) + 2. --> 3 | |
-- Combinatory parsing? | |
class Parser inherits BaseParser { | |
init: source => grammar source. | |
grammar: ps => (expression ps) | (statement ps). | |
} | |
-- Lambdas | |
fac <- { n => (n = 0) then: { 1 } | |
else: { fac ((n - 1) * n) }}. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment