Skip to content

Commit

Permalink
Merge from v0_9_4 to HEAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquark committed Sep 20, 2008
1 parent f181e52 commit a51af6f
Show file tree
Hide file tree
Showing 46 changed files with 640 additions and 172 deletions.
1 change: 1 addition & 0 deletions OrcJava/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<classpathentry exported="true" kind="lib" path="lib/args4j-2.0.9.jar"/>
<classpathentry exported="true" kind="lib" path="lib/rats-runtime.jar"/>
<classpathentry exported="true" kind="lib" path="lib/kilimex-runtime.jar"/>
<classpathentry kind="lib" path="lib/junit-4.5.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>
2 changes: 1 addition & 1 deletion OrcJava/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ orc.location.lib=lib
# source code
orc.location.src=src
# javadoc
orc.location.javadoc=doc/javadoc
orc.location.javadoc=build/javadoc
19 changes: 12 additions & 7 deletions OrcJava/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
<target name="jar" depends="kilim" description="generate the distribution">
<!-- Put everything in ${orc.location.build} into orc-sites.jar -->
<jar jarfile="${ant.project.name}-${orc.version}.jar" basedir="${orc.location.build}">
<exclude name="orc/test/**"/>
<!-- Include library dependencies -->
<zipgroupfileset dir="${orc.location.lib}">
<include name="*.jar"/>
<exclude name="rats.jar"/>
<exclude name="kilimex.jar"/>
<exclude name="junit-*.jar"/>
</zipgroupfileset>
<manifest>
<attribute name="Main-Class" value="orc.Orc"/>
Expand All @@ -26,13 +28,15 @@
</target>

<target name="zip" depends="jar" description="generate the ZIP">
<zip basedir="." zipfile="${ant.project.name}-${orc.version}.zip">
<include name="${ant.project.name}-${orc.version}.jar"/>
<include name="README"/>
<include name="LICENSE"/>
<include name="INSTALL"/>
<include name="examples/**"/>
<include name="doc/**"/>
<zip zipfile="${ant.project.name}-${orc.version}.zip">
<zipfileset prefix="${ant.project.name}-${orc.version}" dir=".">
<include name="${ant.project.name}-${orc.version}.jar"/>
<include name="README"/>
<include name="LICENSE"/>
<include name="INSTALL"/>
<include name="examples/**/*.orc"/>
<include name="doc/**/*.pdf"/>
</zipfileset>
</zip>
</target>

Expand Down Expand Up @@ -87,5 +91,6 @@
version="true">
<classpath refid="orc.classpath"/>
</javadoc>
<zip zipfile="${ant.project.name}-${orc.version}-doc.zip" basedir="${orc.location.javadoc}" />
</target>
</project>
Binary file added OrcJava/doc/userguide.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions OrcJava/examples/buffer.orc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
val c = Buffer()
c.get() | Rtimer(3000) >> c.put(3) >> stop

{-
OUTPUT:
3
-}
8 changes: 7 additions & 1 deletion OrcJava/examples/curried.orc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ def adder1(x)(y) = x + y
val adder2 = lambda(x)(y) = x + y

adder1(5) >a> a(2)
| adder2(5) >a> a(2)
| adder2(5) >a> a(2)

{-
OUTPUT:
7
7
-}
11 changes: 10 additions & 1 deletion OrcJava/examples/ifthenelse.orc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ def downfrom(n) =
then 0
else (n | downfrom(n-1))

downfrom(5)
downfrom(5)
{-
OUTPUT:
5
4
3
2
1
0
-}
33 changes: 30 additions & 3 deletions OrcJava/examples/isprime.orc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,35 @@ def isPrime(n) =
if(b) >> (n % i /= 0) && primeat(i+1)
| if(~b) >> true
primeat(2)

def Metronome(i) = i | Rtimer(500) >> Metronome(i+1)

-- Publish only prime numbers
Metronome(2) >n> if(isPrime(n)) >> n
each(range(1, 100)) >n> if(isPrime(n)) >> n
{-
OUTPUT:
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
-}
8 changes: 7 additions & 1 deletion OrcJava/examples/java_array.orc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ a.set(1, 1) >>
a.set(2, 2) >>
a.set(3, 3) >>
a.slice(1,4) >b>
each(b)
each(b)
{-
OUTPUT:
1
2
3
-}
11 changes: 9 additions & 2 deletions OrcJava/examples/java_io.orc
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ def GetContent(in) =
loop(in.read(buf)) >>
out.toString()

InputStreamReader(FileInputStream("examples/java_io.orc")) >reader>
GetContent(reader)
InputStreamReader(FileInputStream("examples/java_io_sample.txt")) >reader>
GetContent(reader)
{-
OUTPUT:
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
-}
4 changes: 4 additions & 0 deletions OrcJava/examples/java_io_sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
7 changes: 6 additions & 1 deletion OrcJava/examples/java_null.orc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
println(cat(Null())) >> stop
| Null()
| Null()
{-
OUTPUT:
null
null
-}
37 changes: 24 additions & 13 deletions OrcJava/examples/java_numbers.orc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@ class Long = java.lang.Long
class Integer = java.lang.Integer
class Short = java.lang.Short

val x = Integer.valueOf(3)

-- test coercion
3 >x> (
println(x.getClass()) >> stop
| println(Integer.toString(x)) >> stop
)
println(x.getClass()) >>
println(Integer.toString(x)) >>
stop
;
-- test widening
Integer.valueOf(3) >x> (
println(x.getClass()) >> stop
| println(Long.toString(x)) >> stop
| println(Double.toString(x)) >> stop
)
println(x.getClass()) >>
println(Long.toString(x)) >>
println(Double.toString(x)) >>
stop
;
-- test narrowing (error is expected)
Integer.valueOf(3) >x> (
println(x.getClass()) >> stop
| println(Short.toString(x)) >> stop
)
println(x.getClass()) >>
println(Short.toString(x)) >>
stop

{-
OUTPUT:
class java.lang.Integer
3
class java.lang.Integer
3
3.0
class java.lang.Integer
Error: java.lang.IllegalArgumentException: argument type mismatch
Source location: examples/java_numbers.orc:22:9-25
-}
33 changes: 24 additions & 9 deletions OrcJava/examples/kilim.orc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ class KilimBuffer = orc.lib.state.KilimBuffer
val t = KilimExample("hi")
val b = KilimBuffer()

t.sleep(5000) >x> "5 "+x
| t.sleep(2000) >x> "2 "+x
| t.exit() >> t.signal() -- should not publish
| t.error() >> t.signal() -- should not publish
| t.signal() -- should publish
| t.sleepThread(1000) >x> "1 "+x
| t.sleepThread(1000) >x> "1 "+x
| t.sleep(3000) >> b.put("3 buffered") >> stop
| b.get()
(
t.exit() >> t.signal() -- should not publish
| t.error() >> t.signal() -- should not publish
) ; (
t.signal() -- should publish
| t.sleep(5000) >x> "5 "+x
| t.sleep(2000) >x> "2 "+x
| t.sleepThread(1000) >x> "1 "+x
| t.sleepThread(1000) >x> "1 "+x
| t.sleep(3000) >> b.put("3 buffered") >> stop
| b.get()
)

{-
OUTPUT:
Error: java.lang.Exception: ERROR
Source location: examples/kilim.orc:9:5-14
signal
1 hi
1 hi
2 hi
3 buffered
5 hi
-}
15 changes: 14 additions & 1 deletion OrcJava/examples/lambda.orc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,17 @@ def Counter(n) =
nr.get() >!n>
nr.put(n+1) >> stop)

Counter(0) >c> Metronome() >> c()
Counter(0) >c> each(range(1,10)) >> c()
{-
OUTPUT:
0
1
2
3
4
5
6
7
8
9
-}
7 changes: 6 additions & 1 deletion OrcJava/examples/patterns/bang.orc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-- Using '!' to publish matching results as they match.
-- Note: '!' will only release these publications if the whole pattern succeeds.
-- Output: 2 and true and (2,2)

{-
OUTPUT:
true
2
(2, 2)
-}
( (1,2,true) | (2,5,true) ) >(1,!x,!true)> (x,x)
6 changes: 5 additions & 1 deletion OrcJava/examples/patterns/filter1.orc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- Filter using literal match, push
-- Output: 4 and 6
{-
OUTPUT:
4
6
-}
( (1,4) | (2,5) | (1,6) ) >(1,x)> x

7 changes: 5 additions & 2 deletions OrcJava/examples/patterns/filter2.orc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-- Filter using literal match, pull
-- Output: Either 4 or 6
x <(1,x)< ( (1,4) | (2,5) | (1,6) )
{-
OUTPUT:
4
-}
x <(1,x)< ( (1,4) | (2,5) | (1,6) )

6 changes: 5 additions & 1 deletion OrcJava/examples/patterns/filter3.orc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- Filter using size match, push
-- Output: (6,5) and (2,1)
{-
OUTPUT:
(2, 1)
(6, 5)
-}
( (1,2) | (1,2,3) | (5,6) | (5,6,7) ) >(x,y)> (y,x)

7 changes: 5 additions & 2 deletions OrcJava/examples/patterns/filter_lists.orc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-- Filtration based on list structure
-- Output: (1,2,[3]) and (4,5,[])

{-
OUTPUT:
(4, 5, [])
(1, 2, [3])
-}
( [1,2,3] | [4,5] | [6] | [] ) >a:b:c> (a,b,c)
15 changes: 12 additions & 3 deletions OrcJava/examples/patterns/java_lists.orc
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
-- some interleaving of of 1 2 3 with 1 2 3
-- followed by 1 2 3

{-
OUTPUT:
1
1
2
2
3
3
1
2
3
-}
class LinkedList = java.util.LinkedList
val l = LinkedList()

Expand Down
10 changes: 8 additions & 2 deletions OrcJava/examples/patterns/lists1.orc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
-- Create some lists
-- Output: [] and [7] and [1,2,3] and [1,5,8] and [[1],4,6]

{-
OUTPUT:
[]
[7]
[1, 2, 3]
[[1], 4, 6]
[1, 5, 8]
-}
[1,2,3] | [1]:4:[6] | 1:5:8:[] | [] | [7]


Expand Down
5 changes: 4 additions & 1 deletion OrcJava/examples/patterns/lists2.orc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- Pattern matching on a list
-- Output: ([4],3,2,1)
{-
OUTPUT:
([4], 3, 2, 1)
-}
[1,2,3,4] >a:t> t >b:c:u> (u,c,b,a)
9 changes: 6 additions & 3 deletions OrcJava/examples/patterns/subpat.orc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-- Using 'as' to capture sub-patterns
-- Output: (1,2,3,(2,3)) and (4,5,6,(5,6))

( (1,(2,3)) | (4,(5,6)) | (7,8,9) ) >(a,(b,c) as d)> (a,b,c,d)
{-
OUTPUT:
(1, 2, 3, (2, 3))
(4, 5, 6, (5, 6))
-}
( (1,(2,3)) | (4,(5,6)) ) >(a,(b,c) as d)> (a,b,c,d)
Loading

0 comments on commit a51af6f

Please sign in to comment.