diff --git a/OrcJava/src/orc/doc/DocParser.rats b/OrcJava/src/orc/doc/DocParser.rats index 3e11637a4..63e0f6f58 100644 --- a/OrcJava/src/orc/doc/DocParser.rats +++ b/OrcJava/src/orc/doc/DocParser.rats @@ -38,9 +38,14 @@ List DocumentationBlock = ; DocNode DocNode = - lead:StartDocType type:RestOfLine EndLine? BlankLine* { - int depth = lead.trim().length(); - yyValue = new DocType(depth, type); + "@site" Space type:RestOfLine EndLine? BlankLine* { + yyValue = new DocType(1, "site " + type); + } + / "@def" Space type:RestOfLine EndLine? BlankLine* { + yyValue = new DocType(1, "def " + type); + } + / "@method" Space type:RestOfLine EndLine? BlankLine* { + yyValue = new DocType(2, "site " + type); } / "@" name:Identifier { yyValue = new DocTag(name); @@ -50,7 +55,7 @@ DocNode DocNode = } ; -String DocParagraph = (XML / !(EndDoc / EndLine (StartDocType / BlankLine)) _)+ ; +String DocParagraph = (XML / !(EndDoc / EndLine BlankLine) _)+ ; String DocCode = (!StartDoc (EndLineComment / MultiLineComment / StringLiteral / _))+; @@ -63,7 +68,6 @@ String XML = ; -String StartDocType = "*"+ Space ; transient String StartDoc = "{--" Space? ; transient String EndDoc = Space? [\-]+ [}] ; transient String BlankLine = Space? EndLine ; diff --git a/OrcJava/src/orc/doc/MakeDoc.java b/OrcJava/src/orc/doc/MakeDoc.java index 6d85ec8e9..d85b3713b 100644 --- a/OrcJava/src/orc/doc/MakeDoc.java +++ b/OrcJava/src/orc/doc/MakeDoc.java @@ -94,10 +94,10 @@ public static String extractName(String type) { // extract everything between the declaration keyword // and the argument list return type.replaceAll("[a-z]+\\s+(.[^(]+).*", "$1") - // drop the method receiver type - .replaceFirst("^[^.]+\\.", "") // drop type parameters - .replaceFirst("\\[[^\\]]+\\]", ""); + .replaceFirst("\\[[^\\]]+\\]", "") + // drop the method receiver type + .replaceFirst("^[^.]+\\.", ""); } public static String firstSentence(String para) { diff --git a/OrcJava/src/orc/inc/prelude/core.inc b/OrcJava/src/orc/inc/prelude/core.inc index 981b7f301..2d7bfb359 100644 --- a/OrcJava/src/orc/inc/prelude/core.inc +++ b/OrcJava/src/orc/inc/prelude/core.inc @@ -22,19 +22,19 @@ type Top = orc.type.ground.Top type Bot = orc.type.ground.Bot {-- -* site let() :: Top +@site let() :: Top When applied to no arguments, return a signal. -* site let[A](A) :: A +@site let[A](A) :: A When applied to a single argument, return that argument (behaving as the identity function). -* site let[A, ...](A, ...) :: (A, ...) +@site let[A, ...](A, ...) :: (A, ...) When applied to zero, two, or more arguments, return the arguments in a tuple. --} site let = orc.runtime.sites.core.Let {-- -* site if(Boolean) :: Top +@site if(Boolean) :: Top Fail silently if the argument is false. Otherwise return a signal. Example: @@ -46,7 +46,7 @@ Example: site if = orc.runtime.sites.core.If {-- -* site error(String) :: Bot +@site error(String) :: Bot Halt with the given error message. Example, using error to implement assertions: @@ -60,19 +60,19 @@ assert(false)]]> site error = orc.runtime.sites.core.Error {-- -* site (+)(Number, Number) :: Number +@site (+)(Number, Number) :: Number a+b returns the sum of a and b. --} site (+) = orc.lib.math.Add {-- -* site (-)(Number, Number) :: Number +@site (-)(Number, Number) :: Number a-b returns the value of a minus the value of b. --} site (-) = orc.lib.math.Sub {-- -* site (0-)(Number) :: Number +@site (0-)(Number) :: Number Return the additive inverse of the argument. When this site appears as an operator, it is written in prefix form without the zero, i.e. (-a) @@ -80,13 +80,13 @@ zero, i.e. (-a) site (0-) = orc.lib.math.UMinus {-- -* site (*)(Number, Number) :: Number +@site (*)(Number, Number) :: Number a*b returns the product of a and b. --} site (*) = orc.lib.math.Mult {-- -* site (**)(Number, Number) :: Number +@site (**)(Number, Number) :: Number a ** b returns ab, i.e. a raised to the bth power. @@ -94,7 +94,7 @@ i.e. a raised to the bth power. site (**) = orc.lib.math.Exponent {-- -* site (/)(Number, Number) :: Number +@site (/)(Number, Number) :: Number a/b returns a divided by b. If both arguments have integral types, (/) performs integral division, rounding towards zero. Otherwise, it performs floating-point @@ -108,7 +108,7 @@ Example: site (/) = orc.lib.math.Div {-- -* site (%)(Number, Number) :: Number +@site (%)(Number, Number) :: Number a%b computes the remainder of a/b. If a and b have integral types, then the remainder is given by the expression a - (a/b)*b. For a full description, see the @@ -117,31 +117,31 @@ the expression a - (a/b)*b. For a full description, see the site (%) = orc.lib.math.Mod {-- -* site (<)(Top, Top) :: Boolean +@site (<)(Top, Top) :: Boolean a < b returns true if a is less than b, and false otherwise. --} site (<) = orc.lib.comp.Less {-- -* site (<=)(Top, Top) :: Boolean +@site (<=)(Top, Top) :: Boolean a <= b returns true if a is less than or equal to b, and false otherwise. --} site (<=) = orc.lib.comp.Leq {-- -* site (>)(Top, Top) :: Boolean +@site (>)(Top, Top) :: Boolean a > b returns true if a is greater than b, and false otherwise. --} site (>) = orc.lib.comp.Greater {-- -* site (>=)(Top, Top) :: Boolean +@site (>=)(Top, Top) :: Boolean a >= b returns true if a is greater than or equal to b, and false otherwise. --} site (>=) = orc.lib.comp.Greq {-- -* site (=)(Top, Top) :: Boolean +@site (=)(Top, Top) :: Boolean a = b returns true if a is equal to b, and false otherwise. The precise definition of "equal" depends on the values being compared, but always obeys the rule that if two values are considered @@ -161,19 +161,19 @@ always considered inequal, i.e. the comparison will return false. site (=) = orc.runtime.sites.core.Equal {-- -* site (/=)(Top, Top) :: Boolean +@site (/=)(Top, Top) :: Boolean a/=b returns false if a=b, and true otherwise. --} site (/=) = orc.runtime.sites.core.Inequal {-- -* site (~)(Boolean) :: Boolean +@site (~)(Boolean) :: Boolean Return the logical negation of the argument. --} site (~) = orc.runtime.sites.core.Not {-- -* site (&&)(Boolean, Boolean) :: Boolean +@site (&&)(Boolean, Boolean) :: Boolean Return the logical conjunction of the arguments. This is not a short-circuiting operator; both arguments must be evaluated and available before the result is computed. @@ -181,7 +181,7 @@ computed. site (&&) = orc.lib.bool.And {-- -* site (||)(Boolean, Boolean) :: Boolean +@site (||)(Boolean, Boolean) :: Boolean Return the logical disjunction of the arguments. This is not a short-circuiting operator; both arguments must be evaluated and available before the result is computed. @@ -189,7 +189,7 @@ computed. site (||) = orc.lib.bool.Or {-- -* site (:)[A](A, List[A]) :: List[A] +@site (:)[A](A, List[A]) :: List[A] The list a:b is formed by prepending the element a to the list b. @@ -212,7 +212,7 @@ and will probably change in future versions of the implementation. site (:) = orc.runtime.sites.core.Cons {-- -* def abs(Number) :: Number +@def abs(Number) :: Number Return the absolute value of the argument. @implementation @@ -221,7 +221,7 @@ def abs(Number) :: Number def abs(x) = if x < 0 then -x else x {-- -* def signum(Number) :: Number +@def signum(Number) :: Number signum(a) returns -1 if a<0, 1 if a>0, and 0 if a=0. @@ -234,7 +234,7 @@ def signum(x) = else 0 {-- -* def min[A](A,A) :: A +@def min[A](A,A) :: A Return the lesser of the arguments. If the arguments are equal, return the first argument. @@ -244,7 +244,7 @@ def min[A](A,A) :: A def min(x,y) = if y < x then y else x {-- -* def max[A](A,A) :: A +@def max[A](A,A) :: A Return the greater of the arguments. If the arguments are equal, return the second argument. @@ -255,14 +255,14 @@ def max(x,y) = if x > y then x else y {-- -* site floor(Number) :: Integer +@site floor(Number) :: Integer Return the greatest integer less than or equal to this number. --} site floor = orc.lib.math.Floor {-- -* site ceil(Number) :: Integer +@site ceil(Number) :: Integer Return the least integer greater than or equal to this number. --} diff --git a/OrcJava/src/orc/inc/prelude/data.inc b/OrcJava/src/orc/inc/prelude/data.inc index 6de4527b2..9c67a70e3 100644 --- a/OrcJava/src/orc/inc/prelude/data.inc +++ b/OrcJava/src/orc/inc/prelude/data.inc @@ -6,7 +6,7 @@ General-purpose supplemental data structures. type List = orc.type.ListType {-- -* site Semaphore(Integer) :: Semaphore +@site Semaphore(Integer) :: Semaphore Return a semaphore with the given value. The semaphore maintains the invariant that its value is always non-negative. @@ -21,24 +21,24 @@ println("Entering critical section") >> println("Leaving critical section") >> lock.release()]]> -** site Semaphore.acquire() :: Top +@method Semaphore.acquire() :: Top If the semaphore's value is greater than 0, decrement the semaphore and return a signal. If the semaphore's value is 0, block until it becomes greater than 0. -** site Semaphore.acquirenb() :: Top +@method Semaphore.acquirenb() :: Top If the semaphore's value is greater than 0, decrement the semaphore and return a signal. If the semaphore's value is 0, halt. -** site Semaphore.release() :: Top +@method Semaphore.release() :: Top If any calls to acquire are blocked, allow the oldest such call to return. Otherwise, increment the value of the semaphore. This may increment the value beyond that with which the semaphore was constructed. -** site Semaphore.snoop() :: Top +@method Semaphore.snoop() :: Top If any calls to acquire are blocked, return a signal. Otherwise, block until some call to acquire blocks. -** site Semaphore.snoopnb() :: Top +@method Semaphore.snoopnb() :: Top If any calls to acquire are blocked, return a signal. Otherwise, halt. --} @@ -46,7 +46,7 @@ site Semaphore = orc.lib.state.Semaphore type Semaphore = orc.lib.state.types.SemaphoreType {-- -* site Buffer[A]() :: Buffer[A] +@site Buffer[A]() :: Buffer[A] Create a new buffer (FIFO channel) of unlimited size. A buffer supports @@ -65,36 +65,36 @@ val b = Buffer() Rtimer(1000) >> b.put(10) >> stop | b.get()]]> -** site Buffer[A].get() :: A +@method Buffer[A].get() :: A Get an item from the buffer. If the buffer is open and no items are available, block until one becomes available. If the buffer is closed and no items are available, halt. -** site Buffer[A].getnb() :: A +@method Buffer[A].getnb() :: A Get an item from the buffer. If no items are available, halt. -** site Buffer[A].put(A) :: Top +@method Buffer[A].put(A) :: Top Put an item in the buffer. If the buffer is closed, halt. -** site Buffer[A].close() :: Top +@method Buffer[A].close() :: Top Close the buffer and block until it is empty. This has the effect of immediately causing any blocked calls to get to halt. In addition, any subsequent calls to put will halt, and once the buffer becomes empty, any subsequent calls to get will halt. -** site Buffer[A].closenb() :: Top +@method Buffer[A].closenb() :: Top Close the buffer and return a signal immediately. This has the effect of immediately causing any blocked calls to get to halt. In addition, any subsequent calls to put will halt, and once the buffer becomes empty, any subsequent calls to get will halt. -** site Buffer[A].isClosed() :: Boolean +@method Buffer[A].isClosed() :: Boolean If the buffer is currently closed, return true, otherwise return false. -** site Buffer[A].getAll() :: List[A] +@method Buffer[A].getAll() :: List[A] Get all of the items currently in the buffer, emptying the buffer and returning a list of the items in the order they were added. If there are no items in the buffer, return an empty list. @@ -103,7 +103,7 @@ site Buffer = orc.lib.state.Buffer type Buffer = orc.lib.state.types.BufferType {-- -* site BoundedBuffer[A](Integer) :: BoundedBuffer[A] +@site BoundedBuffer[A](Integer) :: BoundedBuffer[A] Create a new buffer (FIFO channel) with the given number of slots. Putting an item into the buffer fills a slot, and getting an item opens a slot. A buffer with zero slots is equivalent to a @@ -126,23 +126,23 @@ val c = BoundedBuffer(1) | c.get() >n> "Got " + n )]]> -** site BoundedBuffer[A].get() :: A +@method BoundedBuffer[A].get() :: A Get an item from the buffer. If the buffer is open and no items are available, block until one becomes available. If the buffer is closed and no items are available, halt. -** site BoundedBuffer[A].getnb() :: A +@method BoundedBuffer[A].getnb() :: A Get an item from the buffer. If no items are available, halt. -** site BoundedBuffer[A].put(A) :: Top +@method BoundedBuffer[A].put(A) :: Top Put an item in the buffer. If no slots are open, block until one becomes open. If the buffer is closed, halt. -** site BoundedBuffer[A].putnb(A) :: Top +@method BoundedBuffer[A].putnb(A) :: Top Put an item in the buffer. If no slots are open, halt. If the buffer is closed, halt. -** site BoundedBuffer[A].close() :: Top +@method BoundedBuffer[A].close() :: Top Close the buffer and block until it is empty. @@ -153,7 +153,7 @@ will halt, and once the buffer becomes empty, any subsequent calls to initiated prior to closing the buffer may still be allowed to return as usual. -** site BoundedBuffer[A].closenb() :: Top +@method BoundedBuffer[A].closenb() :: Top Close the buffer and return a signal immediately. This has the effect of immediately causing any blocked calls to get to halt. In addition, any subsequent calls to put @@ -161,18 +161,18 @@ will halt, and once the buffer becomes empty, any subsequent calls to get will halt. Note that any blocked calls to put initiated prior to closing the buffer may still be allowed to return as usual. -** site BoundedBuffer[A].isClosed() :: Boolean +@method BoundedBuffer[A].isClosed() :: Boolean If the buffer is currently closed, return true, otherwise return false. -** site BoundedBuffer[A].getOpen() :: Integer +@method BoundedBuffer[A].getOpen() :: Integer Return the number of open slots in the buffer. Because of concurrency this value may become out-of-date so it should only be used for debugging or statistical measurements. -** site BoundedBuffer[A].getBound() :: Integer +@method BoundedBuffer[A].getBound() :: Integer Return the total number of slots (open or filled) in the buffer. -** site BoundedBuffer[A].getAll() :: [A] +@method BoundedBuffer[A].getAll() :: [A] Get all of the items currently in the buffer or waiting to be added, emptying the buffer and returning a list of the items in the order they were added. If there are no items in the buffer or waiting to be added, return an empty list. @@ -181,7 +181,7 @@ site BoundedBuffer = orc.lib.state.BoundedBuffer type BoundedBuffer = orc.lib.state.types.BoundedBufferType {-- -* site SyncChannel[A]() :: SyncChannel[A] +@site SyncChannel[A]() :: SyncChannel[A] Create a synchronous channel, or rendezvous. @@ -194,17 +194,17 @@ val c = SyncChannel() c.put(10) | Rtimer(1000) >> c.get()]]> -** site SyncChannel[A].get() :: A +@method SyncChannel[A].get() :: A Receive an item over the channel. If no sender is available, block until one becomes available. -** site SyncChannel[A].put(A) :: Top +@method SyncChannel[A].put(A) :: Top Send an item over the channel. If no receiver is available, block until one becomes available. --} site SyncChannel = orc.lib.state.SyncChannel type SyncChannel = orc.lib.state.types.SyncChannelType {-- -* site Cell[A]() :: Cell[A] +@site Cell[A]() :: Cell[A] Create a write-once storage location. Example: @@ -214,20 +214,20 @@ val c = Cell() c.write(5) >> c.read() | Rtimer(1) >> ( c.write(10) ; c.read() )]]> -** site Cell[A].read() :: A +@method Cell[A].read() :: A Read a value from the cell. If the cell does not yet have a value, block until it receives one. -** site Cell[A].readnb() :: A +@method Cell[A].readnb() :: A Read a value from the cell. If the cell does not yet have a value, halt. -** site Cell[A].write() :: Top +@method Cell[A].write() :: Top Write a value to the cell. If the cell already has a value, halt. --} site Cell = orc.lib.state.Cell type Cell = orc.lib.state.types.CellType {-- -* site Ref[A]() :: Ref[A] +@site Ref[A]() :: Ref[A] Create a rewritable storage location without an initial value. @@ -241,16 +241,16 @@ Rtimer(1000) >> r := 5 >> stop println(r?) >> stop]]> -** site Ref[A](A) :: Ref[A] +@method Ref[A](A) :: Ref[A] Create a rewritable storage location initialized to the provided value. -** site Ref[A].read() :: A +@method Ref[A].read() :: A Read the value of the ref. If the ref does not yet have a value, block until it receives one. -** site Ref[A].readnb() :: A +@method Ref[A].readnb() :: A Read the value of the ref. If the ref does not yet have a value, halt. -** site Ref[A].write(A) :: Top +@method Ref[A].write(A) :: Top Write a value to the ref. --} @@ -258,7 +258,7 @@ site Ref = orc.lib.state.Ref type Ref = orc.lib.state.types.RefType {-- -** def (?)[A](Ref[A]) :: A +@def (?)[A](Ref[A]) :: A Get the value held by a reference. x? is equivalent to x.read(). @@ -268,7 +268,7 @@ def (?)[A](Ref[A]) :: A def (?)(r) = r.read() {-- -** def (:=)[A](Ref[A], A) :: Top +@def (:=)[A](Ref[A], A) :: Top Set the value held by a reference. x := y is equivalent to x.write(y). @@ -278,7 +278,7 @@ def (:=)[A](Ref[A], A) :: Top def (:=)(r,v) = r.write(v) {-- -* site Array[A](Integer) :: Array[A] +@site Array[A](Integer) :: Array[A] Create a new native array of the given size. The array is initialized to contain nulls. @@ -305,7 +305,7 @@ a(i) := f(i) >> stop ; a(0)? | a(1)? | a(2)?]]> -** site Array[A](Integer, String) :: Array[A] +@method Array[A](Integer, String) :: Array[A] Create a new primitive array of the given size with the given primitive type. The initial values in the array depend on the primitive type: for numeric types, it is 0; for booleans, false; for chars, the character @@ -316,22 +316,22 @@ primitive type, although a typechecker may not be able to verify this. This constructor is only necessary when interfacing with certain Java libraries; most programs will just use the Array(Integer) constructor. -** site Array[A].get(Integer) :: A +@method Array[A].get(Integer) :: A Get the element of the array given by the index, counting from 0. a.get(i) is equivalent to a(i)?. -** site Array[A].set(Integer, A) :: Top +@method Array[A].set(Integer, A) :: Top Set the element of the array given by the index, counting from 0. a.set(i,v) is equivalent to a(i) := v. -** site Array[A].slice(Integer, Integer) :: Array[A] +@method Array[A].slice(Integer, Integer) :: Array[A] Return a copy of the portion of the array with indices covered by the given half-open range. The result array is still indexed counting from 0. -** site Array[A].length() :: Integer +@method Array[A].length() :: Integer Return the size of the array. -** site Array[A].fill(A) :: Top +@method Array[A].fill(A) :: Top Set every element of the array to the given value. The given value is not copied, but is shared by every element of the array, so for example a.fill(Semaphore(1)) would allow you to access the same semaphore @@ -349,7 +349,7 @@ site Array = orc.lib.util.JavaArray type Array = orc.lib.state.types.ArrayType {-- -* def IArray[A](Integer, lambda (Integer) :: A)(Integer) :: A +@def IArray[A](Integer, lambda (Integer) :: A)(Integer) :: A The call IArray(n,f), where n is a natural number and f a total function over natural numbers, creates and returns a partial, pre-computed version of f @@ -379,7 +379,7 @@ def IArray(n, f) = fill(n-1, f) >> a.get {-- -* site Some[A](A) :: Option[A] +@site Some[A](A) :: Option[A] An optional value which is available. This site may also be used in a pattern. @@ -391,7 +391,7 @@ Some((3,4)) >s> ( | s >None()> signal )]]> -* site None[A]() :: Option[A] +@site None[A]() :: Option[A] An optional value which is not available. This site may also be used in a pattern. @@ -401,37 +401,37 @@ site Some = orc.runtime.sites.core.Some site None = orc.runtime.sites.core.None {-- -* site Set[A]() :: Set[A] +@site Set[A]() :: Set[A] Construct an empty mutable set. The set considers two values a and b to be the same if and only if a=b. This site conforms to the Java interface java.util.Set, except that it obeys Orc rules for equality of elements rather than Java rules. -** site Set[A].add(A) :: Boolean +@method Set[A].add(A) :: Boolean Add a value to the set, returning true if the set did not already contain the value, and false otherwise. -** site Set[A].remove(Top) :: Boolean +@method Set[A].remove(Top) :: Boolean Remove a value from the set, returning true if the set contained the value, and false otherwise. -** site Set[A].contains(Top) :: Boolean +@method Set[A].contains(Top) :: Boolean Return true if the set contains the given value, and false otherwise. -** site Set[A].isEmpty() :: Boolean +@method Set[A].isEmpty() :: Boolean Return true if the set contains no values. -** site Set[A].clear() :: Top +@method Set[A].clear() :: Top Remove all values from the set. -** site Set[A].size() :: Integer +@method Set[A].size() :: Integer Return the number of unique values currently contained in the set. --} class Set = orc.lib.data.Set {-- -* site Map[K,V]() :: Map[K,V] +@site Map[K,V]() :: Map[K,V] Construct an empty mutable map from keys to values. Each key contained in the map is associated with exactly one value. The mapping considers two keys a and b to be the same if and only if @@ -439,53 +439,53 @@ map is associated with exactly one value. The mapping considers two keys java.util.Map, except that it obeys Orc rules for equality of keys rather than Java rules. -** site Map[K,V].put(K, V) :: V +@method Map[K,V].put(K, V) :: V map.put(k,v) associates the value v with the key k in map, such that map.get(k) returns v. Return the value previously associated with the key, if any, otherwise return Null(). -** site Map[K,V].get(K) :: V +@method Map[K,V].get(K) :: V Return the value currently associated with the given key, if any, otherwise return Null(). -** site Map[K,V].remove(Top) :: V +@method Map[K,V].remove(Top) :: V Remove the given key from the map. Return the value previously associated with the key, if any, otherwise return Null(). -** site Map[K,V].containsKey(Top) :: Boolean +@method Map[K,V].containsKey(Top) :: Boolean Return true if the map contains the given key, and false otherwise. -** site Map[K,V].isEmpty() :: Boolean +@method Map[K,V].isEmpty() :: Boolean Return true if the map contains no keys. -** site Map[K,V].clear() :: Top +@method Map[K,V].clear() :: Top Remove all keys from the map. -** site Map[K,V].size() :: Integer +@method Map[K,V].size() :: Integer Return the number of unique keys currently contained in the map. --} class Map = orc.lib.data.Map {-- -* site Counter(Integer) :: Counter +@site Counter(Integer) :: Counter Create a new counter initialized to the given value. -** site Counter() :: Counter +@method Counter() :: Counter Create a new counter initialized to zero. -** site Counter.inc() :: Top +@method Counter.inc() :: Top Increment the counter. -** site Counter.dec() :: Top +@method Counter.dec() :: Top If the counter is already at zero, halt. Otherwise, decrement the counter and return a signal. -** site Counter.onZero() :: Top +@method Counter.onZero() :: Top If the counter is at zero, return a signal. Otherwise block until the counter reaches zero. -** site Counter.value() :: Integer +@method Counter.value() :: Integer Return the current value of the counter. Example: @@ -498,7 +498,7 @@ site Counter = orc.lib.state.Counter type Counter = orc.lib.state.types.CounterType {-- -* site Dictionary() :: Dictionary +@site Dictionary() :: Dictionary Create a new dictionary (a mutable map from field names to values), initially empty. The first time each field of the dictionary is accessed (using dot notation), the dictionary creates and returns a new empty s->field instead of s.field when site Dictionary = orc.lib.data.Dictionary {-- -* def fst[A,B]((A,B)) :: A +@def fst[A,B]((A,B)) :: A Return the first element of a pair. @implementation @@ -558,7 +558,7 @@ def fst[A,B]((A,B)) :: A def fst((x,_)) = x {-- -* def snd[A,B]((A,B)) :: B +@def snd[A,B]((A,B)) :: B Return the second element of a pair. @implementation @@ -567,7 +567,7 @@ def snd[A,B]((A,B)) :: B def snd((_,y)) = y {-- -* def swap[A,B]((A,B)) :: (B,A) +@def swap[A,B]((A,B)) :: (B,A) Swap the elements of a pair. @implementation diff --git a/OrcJava/src/orc/inc/prelude/idioms.inc b/OrcJava/src/orc/inc/prelude/idioms.inc index 252417dbe..d52d5b379 100644 --- a/OrcJava/src/orc/inc/prelude/idioms.inc +++ b/OrcJava/src/orc/inc/prelude/idioms.inc @@ -5,13 +5,13 @@ combinators borrowed from Haskell or Scheme. --} {-- -* site apply[A, ..., B](lambda (A, ...) :: B, List[A]) :: B +@site apply[A, ..., B](lambda (A, ...) :: B, List[A]) :: B Apply a function to a list of arguments. --} site apply = orc.lib.util.Apply {-- -* def curry[A,B,C](lambda (A,B) :: C)(A)(B) :: C +@def curry[A,B,C](lambda (A,B) :: C)(A)(B) :: C Curry a function of two arguments. @implementation @@ -20,7 +20,7 @@ def curry[A,B,C](lambda (A,B) :: C)(A)(B) :: C def curry(f)(x)(y) = f(x,y) {-- -* def curry3[A,B,C,D](lambda (A,B,C) :: D)(A)(B)(C) :: D +@def curry3[A,B,C,D](lambda (A,B,C) :: D)(A)(B)(C) :: D Curry a function of three arguments. @implementation @@ -29,7 +29,7 @@ def curry3[A,B,C,D](lambda (A,B,C) :: D)(A)(B)(C) :: D def curry3(f)(x)(y)(z) = f(x,y,z) {-- -* def uncurry[A,B,C](lambda (A)(B) :: C)(A, B) :: C +@def uncurry[A,B,C](lambda (A)(B) :: C)(A, B) :: C Uncurry a function of two arguments. @implementation @@ -38,7 +38,7 @@ def uncurry[A,B,C](lambda (A)(B) :: C)(A, B) :: C def uncurry(f)(x,y) = f(x)(y) {-- -* def uncurry3[A,B,C,D](lambda (A)(B)(C) :: D)(A,B,C) :: D +@def uncurry3[A,B,C,D](lambda (A)(B)(C) :: D)(A,B,C) :: D Uncurry a function of three arguments. @implementation @@ -47,7 +47,7 @@ def uncurry3[A,B,C,D](lambda (A)(B)(C) :: D)(A,B,C) :: D def uncurry3(f)(x,y,z) = f(x)(y)(z) {-- -* def flip[A,B,C](lambda (A, B) :: C)(B, A) :: C +@def flip[A,B,C](lambda (A, B) :: C)(B, A) :: C Flip the order of parameters of a two-argument function. @implementation @@ -56,7 +56,7 @@ def flip[A,B,C](lambda (A, B) :: C)(B, A) :: C def flip(f)(x,y) = f(y,x) {-- -* def constant[A](A)() :: A +@def constant[A](A)() :: A Create a function which returns a constant value. @implementation @@ -65,7 +65,7 @@ def constant[A](A)() :: A def constant(x)() = x {-- -* def defer[A,B](lambda (A) :: B, A)() :: B +@def defer[A,B](lambda (A) :: B, A)() :: B Given a function and its argument, return a thunk which applies the function. @implementation @@ -74,7 +74,7 @@ def defer[A,B](lambda (A) :: B, A)() :: B def defer(f, x)() = f(x) {-- -* def defer2[A,B,C](lambda (A,B) :: C, A, B)() :: C +@def defer2[A,B,C](lambda (A,B) :: C, A, B)() :: C Given a function and its arguments, return a thunk which applies the function. @implementation @@ -83,7 +83,7 @@ def defer2[A,B,C](lambda (A,B) :: C, A, B)() :: C def defer2(f, x, y)() = f(x, y) {-- -* def ignore[A,B](lambda () :: B)(A) :: B +@def ignore[A,B](lambda () :: B)(A) :: B From a function of no arguments, create a function of one argument, which is ignored. @@ -93,7 +93,7 @@ def ignore[A,B](lambda () :: B)(A) :: B def ignore(f)(_) = f() {-- -* def ignore2[A,B,C](lambda () :: C)(A, B) :: C +@def ignore2[A,B,C](lambda () :: C)(A, B) :: C From a function of no arguments, create a function of two arguments, which are ignored. @@ -103,7 +103,7 @@ def ignore2[A,B,C](lambda () :: C)(A, B) :: C def ignore2(f)(_, _) = f() {-- -* def compose[A,B,C](lambda (B) :: C, lambda (A) :: B)(A) :: C +@def compose[A,B,C](lambda (B) :: C, lambda (A) :: B)(A) :: C Compose two single-argument functions. @implementation @@ -112,7 +112,7 @@ def compose[A,B,C](lambda (B) :: C, lambda (A) :: B)(A) :: C def compose(f,g)(x) = f(g(x)) {-- -* def while[A](lambda (A) :: Boolean, lambda (A) :: A)(A) :: A +@def while[A](lambda (A) :: Boolean, lambda (A) :: A)(A) :: A Iterate a function while a predicate is satisfied, publishing each value passed to the function. The exact behavior is specified @@ -140,7 +140,7 @@ def while(p,f) = loop {-- -* def repeat[A](lambda () :: A) :: A +@def repeat[A](lambda () :: A) :: A Call a function sequentially, publishing each value returned by the function. The expression repeat(f) is equivalent to the infinite expression f() >x> ( x | f() >x> ( x | f() >x> ... ) ) @@ -151,7 +151,7 @@ def repeat[A](lambda () :: A) :: A def repeat(f) = f() >!x> repeat(f) {-- -* def fork[A](List[lambda () :: A]) :: A +@def fork[A](List[lambda () :: A]) :: A Call a list of functions in parallel, publishing all values published by the functions. @@ -165,7 +165,7 @@ def fork([]) = stop def fork(p:ps) = p() | fork(ps) {-- -* def forkMap[A,B](lambda (A) :: B, List[A]) :: B +@def forkMap[A,B](lambda (A) :: B, List[A]) :: B Apply a function to a list in parallel, publishing all values published by the applications. @@ -179,7 +179,7 @@ def forkMap(f, []) = stop def forkMap(f, x:xs) = f(x) | forkMap(f, xs) {-- -* def seq[A](List[lambda () :: A]) :: Top +@def seq[A](List[lambda () :: A]) :: Top Call a list of functions in sequence, publishing a signal whenever the last function publishes. The actual publications of the given functions are not @@ -195,7 +195,7 @@ def seq([]) = signal def seq(p:ps) = p() >> seq(ps) {-- -* def seqMap[A,B](lambda (A) :: B, List[A]) :: Top +@def seqMap[A,B](lambda (A) :: B, List[A]) :: Top Apply a function to a list in in sequence, publishing a signal whenever the last application publishes. The actual publications of the given functions are not @@ -211,7 +211,7 @@ def seqMap(f, []) = signal def seqMap(f, x:xs) = f(x) >> seqMap(f, xs) {-- -* def join[A](List[lambda () :: A]) :: Top +@def join[A](List[lambda () :: A]) :: Top Call a list of functions in parallel and publish a signal once all functions have completed. @@ -225,7 +225,7 @@ def join([]) = signal def join(p:ps) = (p(), join(ps)) >> signal {-- -* def joinMap[A,B](lambda (A) :: B, List[A]) :: Top +@def joinMap[A,B](lambda (A) :: B, List[A]) :: Top Apply a function to a list in parallel and publish a signal once all applications have completed. @@ -239,7 +239,7 @@ def joinMap(f, []) = signal def joinMap(f, x:xs) = (f(x), joinMap(f, xs)) >> signal {-- -* def alt[A](List[lambda () :: A]) :: A +@def alt[A](List[lambda () :: A]) :: A Call each function in the list until one publishes. The expression alt([f,g,h]) is equivalent to @@ -252,7 +252,7 @@ def alt([]) = stop def alt(p:ps) = p() ; alt(ps) {-- -* def altMap[A,B](lambda (A) :: B, List[A]) :: B +@def altMap[A,B](lambda (A) :: B, List[A]) :: B Apply the function to each element in the list until one publishes. The expression altMap(f, [a,b,c]) is equivalent to @@ -265,7 +265,7 @@ def altMap(f, []) = stop def altMap(f, x:xs) = f(x) ; altMap(f, xs) {-- -* def por(List[lambda () :: Boolean]) :: Boolean +@def por(List[lambda () :: Boolean]) :: Boolean Parallel or. Evaluate a list of boolean functions in parallel, publishing a value as soon as possible, and terminating any unnecessary ongoing computation. @@ -282,7 +282,7 @@ def por(p:ps) = ) {-- -* def pand(List[lambda () :: Boolean]) :: Boolean +@def pand(List[lambda () :: Boolean]) :: Boolean Parallel and. Evaluate a list of boolean functions in parallel, publishing a value as soon as possible, and terminating any unnecessary ongoing computation. @@ -299,7 +299,7 @@ def pand(p:ps) = ) {-- -* def collect[A](lambda () :: A) :: List[A] +@def collect[A](lambda () :: A) :: List[A] Run a function, collecting all publications in a list. Return the list when the function terminates. diff --git a/OrcJava/src/orc/inc/prelude/list.inc b/OrcJava/src/orc/inc/prelude/list.inc index adbb025a6..601bdedc5 100644 --- a/OrcJava/src/orc/inc/prelude/list.inc +++ b/OrcJava/src/orc/inc/prelude/list.inc @@ -5,7 +5,7 @@ operate on the elements of a list in parallel. --} {-- -* def each[A](List[A]) :: A +@def each[A](List[A]) :: A Publish every value in a list, simultaneously. @implementation @@ -15,7 +15,7 @@ def each([]) = stop def each(h:t) = h | each(t) {-- -* def map[A,B](lambda (A) :: B, List[A]) :: List[B] +@def map[A,B](lambda (A) :: B, List[A]) :: List[B] Apply a function to every element of a list (in parallel), returning a list of the results. @@ -26,7 +26,7 @@ def map(f,[]) = [] def map(f,h:t) = f(h):map(f,t) {-- -* def reverse[A](List[A]) :: List[A] +@def reverse[A](List[A]) :: List[A] Return the reverse of the given list. @implementation @@ -39,7 +39,7 @@ def reverse(l) = tailrev(l,[]) {-- -* def filter[A](lambda (A) :: Boolean, List[A]) :: List[A] +@def filter[A](lambda (A) :: Boolean, List[A]) :: List[A] Return a list containing only those elements which satisfy the predicate. The filter is applied to all list elements in parallel. @@ -52,7 +52,7 @@ def filter(p,x:xs) = if p(x) then x:fxs else fxs {-- -* def head[A](List[A]) :: A +@def head[A](List[A]) :: A Return the first element of a list. @implementation @@ -62,7 +62,7 @@ def head(x:xs) = x def head([]) = error("head: empty list") {-- -* def tail[A](List[A]) :: List[A] +@def tail[A](List[A]) :: List[A] Return all but the first element of a list. @implementation @@ -72,7 +72,7 @@ def tail(x:xs) = xs def tail([]) = error("tail: empty list") {-- -* def init[A](List[A]) :: List[A] +@def init[A](List[A]) :: List[A] Return all but the last element of a list. @implementation @@ -83,7 +83,7 @@ def init([x]) = [] def init(x:xs) = x:init(xs) {-- -* def last[A](List[A]) :: A +@def last[A](List[A]) :: A Return the last element of a list. @implementation @@ -94,7 +94,7 @@ def last([x]) = x def last(x:xs) = last(xs) {-- -* def empty[A](List[A]) :: Boolean +@def empty[A](List[A]) :: Boolean Is the list empty? @implementation @@ -104,7 +104,7 @@ def empty([]) = true def empty(_) = false {-- -* def index[A](List[A], Integer) :: A +@def index[A](List[A], Integer) :: A Return the nth element of a list, counting from 0. @implementation @@ -114,7 +114,7 @@ def index(h:t, 0) = h def index(h:t, n) = index(t, n-1) {-- -* def append[A](List[A], List[A]) :: List[A] +@def append[A](List[A], List[A]) :: List[A] Return the first list concatenated with the second. @implementation @@ -124,7 +124,7 @@ def append([],l) = l def append(h:t,l) = h:append(t,l) {-- -* def foldl[A,B](lambda (B, A) :: B, B, List[A]) :: B +@def foldl[A,B](lambda (B, A) :: B, B, List[A]) :: B Reduce a list using the given left-associative binary operation and initial value. Given the list [x1, x2, x3, ...] and initial value x0, returns f(... f(f(f(x0, x1), x2), x3) ...) @@ -141,7 +141,7 @@ def foldl(f,z,[]) = z def foldl(f,z,x:xs) = foldl(f,f(z,x),xs) {-- -* def foldl1[A](lambda (A, A) :: A, List[A]) :: A +@def foldl1[A](lambda (A, A) :: A, List[A]) :: A A special case of foldl which uses the last element of the list as the initial value. It is an error to call this on an empty list. @@ -152,7 +152,7 @@ def foldl1(f,x:xs) = foldl(f,x,xs) def foldl1(_,[]) = error("foldl1: empty list") {-- -* def foldr[A,B](lambda (A, B) :: B, B, List[A]) :: B +@def foldr[A,B](lambda (A, B) :: B, B, List[A]) :: B Reduce a list using the given right-associative binary operation and initial value. Given the list [..., x3, x2, x1] and initial value x0, returns f(... f(x3, f(x2, f(x1, x0))) ...) @@ -168,7 +168,7 @@ def foldr[A,B](lambda (A, B) :: B, B, List[A]) :: B def foldr(f,z,xs) = foldl(flip(f),z,reverse(xs)) {-- -* def foldr1[A](lambda (A, A) :: A, List[A]) :: A +@def foldr1[A](lambda (A, A) :: A, List[A]) :: A A special case of foldr which uses the last element of the list as the initial value. It is an error to call this on an empty list. @@ -178,7 +178,7 @@ def foldr1[A](lambda (A, A) :: A, List[A]) :: A def foldr1(f,xs) = foldl1(flip(f),reverse(xs)) {-- -* def afold[A](lambda (A, A) :: A, List[A]) :: A +@def afold[A](lambda (A, A) :: A, List[A]) :: A Reduce a non-empty list using the given associative binary operation. This function reduces independent subexpressions in parallel; the calls exhibit a balanced tree structure, so the number of sequential @@ -200,7 +200,7 @@ def afold(f, xs) = {-- -* def cfold[A](lambda (A, A) :: A, List[A]) :: A +@def cfold[A](lambda (A, A) :: A, List[A]) :: A Reduce a non-empty list using the given associative and commutative binary operation. This function opportunistically reduces independent subexpressions in parallel, so the number of sequential reductions performed is as small as possible. For expensive reductions, this @@ -229,7 +229,7 @@ def cfold(f, L) = {-- -* def zip[A,B](List[A], List[B]) :: List[(A,B)] +@def zip[A,B](List[A], List[B]) :: List[(A,B)] Combine two lists into a list of pairs. The length of the shortest list determines the length of the result. @@ -241,7 +241,7 @@ def zip(_,[]) = [] def zip(x:xs,y:ys) = (x,y):zip(xs,ys) {-- -* def unzip[A,B](List[(A,B)]) :: (List[A], List[B]) +@def unzip[A,B](List[(A,B)]) :: (List[A], List[B]) Split a list of pairs into a pair of lists. @implementation @@ -251,7 +251,7 @@ def unzip([]) = ([],[]) def unzip((x,y):z) = (x:xs,y:ys) <(xs,ys)< unzip(z) {-- -* def length[A](List[A]) :: Integer +@def length[A](List[A]) :: Integer Return the number of elements in a list. @implementation @@ -261,7 +261,7 @@ def length([]) = 0 def length(h:t) = 1 + length(t) {-- -* def take[A](Integer, List[A]) :: List[A] +@def take[A](Integer, List[A]) :: List[A] Given a number n and a list l, return the first n elements of l. @@ -273,7 +273,7 @@ def take(_, []) = [] def take(n, x:xs) = x:take(n-1, xs) {-- -* def drop[A](Integer, List[A]) :: List[A] +@def drop[A](Integer, List[A]) :: List[A] Given a number n and a list l, return the elements of l after the first n. @@ -285,7 +285,7 @@ def drop(_, []) = [] def drop(n, x:xs) = drop(n-1, xs) {-- -* def member[A](A, List[A]) :: Boolean +@def member[A](A, List[A]) :: Boolean Return true if the given item is a member of the given list, and false otherwise. @@ -298,7 +298,7 @@ def member(item, h:t) = else member(item, t) {-- -* def merge[A](List[A], List[A]) :: List[A] +@def merge[A](List[A], List[A]) :: List[A] Merge two sorted lists. Example: @@ -312,7 +312,7 @@ def merge[A](List[A], List[A]) :: List[A] def merge(xs,ys) = mergeBy((<), xs, ys) {-- -* def mergeBy[A](lambda (A,A) :: Boolean, List[A], List[A]) :: List[A] +@def mergeBy[A](lambda (A,A) :: Boolean, List[A], List[A]) :: List[A] Merge two lists using the given less-than relation. @implementation @@ -325,7 +325,7 @@ def mergeBy(lt, x:xs, y:ys) = else x:mergeBy(lt,xs,y:ys) {-- -* def sort[A](List[A]) :: List[A] +@def sort[A](List[A]) :: List[A] Sort a list. Example: @@ -339,7 +339,7 @@ def sort[A](List[A]) :: List[A] def sort(xs) = sortBy((<), xs) {-- -* def sortBy[A](lambda (A,A) :: Boolean, List[A]) :: List[A] +@def sortBy[A](lambda (A,A) :: Boolean, List[A]) :: List[A] Sort a list using the given less-than relation. @implementation @@ -353,7 +353,7 @@ def sortBy(lt, xs) = mergeBy(lt, sortBy(lt, front), sortBy(lt, back)) {-- -* def mergeUnique[A](List[A], List[A]) :: List[A] +@def mergeUnique[A](List[A], List[A]) :: List[A] Merge two sorted lists, discarding duplicates. Example: @@ -367,7 +367,7 @@ def mergeUnique[A](List[A], List[A]) :: List[A] def mergeUnique(xs,ys) = mergeUniqueBy((=), (<), xs, ys) {-- -* def mergeUniqueBy[A](lambda (A,A) :: Boolean, lambda (A,A) :: Boolean, List[A], List[A]) :: List[A] +@def mergeUniqueBy[A](lambda (A,A) :: Boolean, lambda (A,A) :: Boolean, List[A], List[A]) :: List[A] Merge two lists, discarding duplicates, using the given equality and less-than relations. @implementation @@ -381,7 +381,7 @@ def mergeUniqueBy(eq, lt, x:xs, y:ys) = else x:mergeUniqueBy(eq,lt,xs,y:ys) {-- -* def sortUnique[A](List[A]) :: List[A] +@def sortUnique[A](List[A]) :: List[A] Sort a list, discarding duplicates. Example: @@ -395,7 +395,7 @@ def sortUnique[A](List[A]) :: List[A] def sortUnique(xs) = sortUniqueBy((=), (<), xs) {-- -* def sortUniqueBy[A](lambda (A,A) :: Boolean, lambda (A,A) :: Boolean, List[A]) :: List[A] +@def sortUniqueBy[A](lambda (A,A) :: Boolean, lambda (A,A) :: Boolean, List[A]) :: List[A] Sort a list, discarding duplicates, using the given equality and less-than relations. @implementation @@ -411,7 +411,7 @@ def sortUniqueBy(eq, lt, xs) = sortUniqueBy(eq, lt, back)) {-- -* def group[A,B](List[(A,B)]) :: List[(A,List[B])] +@def group[A,B](List[(A,B)]) :: List[(A,List[B])] Given a list of pairs, group together the second elements of consecutive pairs with equal first elements. @@ -426,7 +426,7 @@ def group[A,B](List[(A,B)]) :: List[(A,List[B])] def group(xs) = groupBy((=), xs) {-- -* def groupBy[A,B](lambda (A,A) :: Boolean, List[(A,B)]) :: List[(A,List[B])] +@def groupBy[A,B](lambda (A,A) :: Boolean, List[(A,B)]) :: List[(A,List[B])] Given a list of pairs, group together the second elements of consecutive pairs with equal first elements, using the given equality relation. @@ -444,7 +444,7 @@ def groupBy(eq, (k,v):kvs) = helper(k,[v], kvs) {-- -* def rangeBy(Number, Number, Number) :: List[Number] +@def rangeBy(Number, Number, Number) :: List[Number] rangeBy(low, high, skip) returns a sorted list of numbers n which satisfy n = low + skip*i (for some integer i), n >= low, and n < high. @@ -458,7 +458,7 @@ def rangeBy(low, high, skip) = else [] {-- -* def range(Number, Number) :: List[Number] +@def range(Number, Number) :: List[Number] Generate a list of numbers in the given half-open range. @implementation @@ -467,7 +467,7 @@ def range(Number, Number) :: List[Number] def range(low, high) = rangeBy(low, high, 1) {-- -* def any[A](lambda (A) :: Boolean, List[A]) :: Boolean +@def any[A](lambda (A) :: Boolean, List[A]) :: Boolean Return true if any of the elements of the list match the predicate, and false otherwise. The predicate is applied to all elements of the list in parellel; the result is returned as soon as it is known and any unnecessary evaluation of the predicate @@ -485,7 +485,7 @@ def any(p, x:xs) = ) {-- -* def all[A](lambda (A) :: Boolean, List[A]) :: Boolean +@def all[A](lambda (A) :: Boolean, List[A]) :: Boolean Return true if all of the elements of the list match the predicate, and false otherwise. The predicate is applied to all elements of the list in parellel; the result is returned as soon as it is known and any unnecessary evaluation of the predicate @@ -503,7 +503,7 @@ def all(p, x:xs) = ) {-- -* def sum(List[Number]) :: Number +@def sum(List[Number]) :: Number Return the sum of all numbers in a list. The sum of an empty list is 0. @@ -513,7 +513,7 @@ def sum(List[Number]) :: Number def sum(xs) = foldl((+) :: lambda (Number, Number) :: Number, 0, xs) {-- -* def product(List[Number]) :: Number +@def product(List[Number]) :: Number Return the product of all numbers in a list. The product of an empty list is 1. @@ -523,7 +523,7 @@ def product(List[Number]) :: Number def product(xs) = foldl((*) :: lambda (Number, Number) :: Number, 1, xs) {-- -* def and(List[Boolean]) :: Boolean +@def and(List[Boolean]) :: Boolean Return the boolean conjunction of all boolean values in the list. The conjunction of an empty list is true. @@ -535,7 +535,7 @@ def and(false:xs) = false def and(true:xs) = and(xs) {-- -* def or(List[Boolean]) :: Boolean +@def or(List[Boolean]) :: Boolean Return the boolean disjunction of all boolean values in the list. The disjunction of an empty list is false. @@ -547,7 +547,7 @@ def or(true:xs) = true def or(false:xs) = or(xs) {-- -* def minimum[A](List[A]) :: A +@def minimum[A](List[A]) :: A Return the minimum element of a non-empty list. @implementation @@ -556,7 +556,7 @@ def minimum[A](List[A]) :: A def minimum(xs) = foldl1(lambda (x::A, y::A) = min(x,y), xs) {-- -* def maximum[A](List[A]) :: A +@def maximum[A](List[A]) :: A Return the maximum element of a non-empty list. @implementation diff --git a/OrcJava/src/orc/inc/prelude/text.inc b/OrcJava/src/orc/inc/prelude/text.inc index 32dbf16a6..628e6d31d 100644 --- a/OrcJava/src/orc/inc/prelude/text.inc +++ b/OrcJava/src/orc/inc/prelude/text.inc @@ -3,7 +3,7 @@ Operations on strings. --} {-- -* site cat(Top, ...) :: String +@site cat(Top, ...) :: String Return the string representation of one or more values, concatenated. For Java objects, this will call toString() to convert the object to a String. @@ -11,7 +11,7 @@ the object to a String. site cat = orc.lib.str.Cat {-- -* site print(Top, ...) :: Top +@site print(Top, ...) :: Top Print one or more values as strings, concatenated, to standard output. For Java objects, this will call toString() to convert the object to a String. @@ -19,7 +19,7 @@ the object to a String. site print = orc.lib.str.Print {-- -* site println(Top, ...) :: Top +@site println(Top, ...) :: Top Print one or more values as strings, concatenated, to standard output, with each value followed by a newline. For Java objects, this will call toString() to convert @@ -28,7 +28,7 @@ the object to a String. site println = orc.lib.str.Println {-- -* site read[A](String) :: A +@site read[A](String) :: A Given a string representing an Orc value (using standard Orc literal syntax), return the corresponding value. If the argument does not conform to Orc literal syntax, @@ -44,7 +44,7 @@ Example: site read = orc.lib.str.Read {-- -* def lines(String) :: List[String] +@def lines(String) :: List[String] Split a string into lines, which are substrings terminated by an endline or the end of the string. DOS, Mac, and Unix endline conventions are all accepted. @@ -60,7 +60,7 @@ def lines(text) = else out {-- -* def unlines(List[String]) :: String +@def unlines(List[String]) :: String Append a linefeed, "\n", to each string in the sequence and concatenate the results. @@ -71,7 +71,7 @@ def unlines(line:lines) = cat(line, "\n", unlines(lines)) def unlines([]) = "" {-- -* def words(String) :: List[String] +@def words(String) :: List[String] Split a string into words, which are sequences of non-whitespace characters separated by whitespace. @implementation @@ -80,7 +80,7 @@ def words(String) :: List[String] def words(text) = text.trim().split("\\s+") {-- -* def unwords(List[String]) :: String +@def unwords(List[String]) :: String Concatenate a sequence of strings with a single space between each string. diff --git a/OrcJava/src/orc/inc/prelude/time.inc b/OrcJava/src/orc/inc/prelude/time.inc index f1f32249b..259ecc91d 100644 --- a/OrcJava/src/orc/inc/prelude/time.inc +++ b/OrcJava/src/orc/inc/prelude/time.inc @@ -3,13 +3,13 @@ Real and logical time. --} {-- -* site Rtimer(Integer) :: Top +@site Rtimer(Integer) :: Top Publish a signal after the given number of milliseconds. --} site Rtimer = orc.lib.time.Rtimer {-- -* site Clock()() :: Integer +@site Clock()() :: Integer A call to Clock creates a new relative clock. Calling a relative clock returns the number of milliseconds which have elapsed since the @@ -24,7 +24,7 @@ Rtimer(1000) >> c()]]> site Clock = orc.lib.time.Clock {-- -* site Ltimer(Integer) :: Top +@site Ltimer(Integer) :: Top Publish a signal after the given number of logical timesteps. A logical timestep is complete as soon as all outstanding site calls (other than calls to Ltimer) have published. @@ -32,7 +32,7 @@ calls (other than calls to Ltimer) have published. site Ltimer = orc.lib.time.Ltimer {-- -* def withLtimer[A](lambda () :: A) :: A +@def withLtimer[A](lambda () :: A) :: A Run a thunk in the context of a new logical clock. --} def withLtimer[A](lambda () :: A) :: A @@ -46,7 +46,7 @@ def withLtimer(thunk) = x {-- -* def metronome(Integer) :: Top +@def metronome(Integer) :: Top Publish a signal at regular intervals, indefinitely. The period is given by the argument, in milliseconds. --} diff --git a/OrcJava/src/orc/inc/prelude/util.inc b/OrcJava/src/orc/inc/prelude/util.inc index 698b6c346..d189b54d5 100644 --- a/OrcJava/src/orc/inc/prelude/util.inc +++ b/OrcJava/src/orc/inc/prelude/util.inc @@ -3,11 +3,11 @@ Miscellaneous utility functions. --} {-- -* site random() :: Integer +@site random() :: Integer Return a random Integer value chosen from the range of all possible 32-bit Integer values. -* site random(Integer) :: Integer +@site random(Integer) :: Integer Return a pseudorandom, uniformly distributed Integer value between 0 (inclusive) and the specified value (exclusive). If the argument is 0, halt. @@ -15,20 +15,20 @@ If the argument is 0, halt. site random = orc.lib.util.Random {-- -* site urandom() :: Number +@site urandom() :: Number Returns a pseudorandom, uniformly distributed Double value between 0 and 1, inclusive. --} site urandom = orc.lib.util.URandom {-- -* site UUID() :: String +@site UUID() :: String Return a random (type 4) UUID represented as a string. --} site UUID = orc.lib.util.UUID {-- -* site Thread(Top) :: Bot +@site Thread(Top) :: Bot Given a site, return a new site which calls the original site in a separate thread. This is necessary when calling a Java site which does not cooperate with Orc's scheduler @@ -41,7 +41,7 @@ uncooperative sites that can be called simultaneously. site Thread = orc.lib.util.ThreadSite {-- -* site Prompt(String) :: String +@site Prompt(String) :: String Prompt the user for some input. The user may cancel the prompt, in which case the site fails silently. Otherwise their response is returned as soon as it is received. @@ -54,7 +54,7 @@ Prompt("What is your name?")]]> site Prompt = orc.lib.util.Prompt {-- -* def signals(Integer) :: Top +@def signals(Integer) :: Top Publish the given number of signals, simultaneously. Example: @@ -68,7 +68,7 @@ def signals(Integer) :: Top def signals(n) = if n > 0 then (signal | signals(n-1)) {-- -* def for(Integer, Integer) :: Integer +@def for(Integer, Integer) :: Integer Publish all values in the given half-open range, simultaneously. Example: @@ -84,7 +84,7 @@ def for(low, high) = else ( low | for(low+1, high) ) {-- -* def upto(Integer) :: Integer +@def upto(Integer) :: Integer upto(n) publishes all values in the range (0..n-1) simultaneously. @@ -99,7 +99,7 @@ def upto(Integer) :: Integer def upto(high) = for(0, high) {-- -* def fillArray[A](Array[A], lambda (Integer) :: A) :: Array[A] +@def fillArray[A](Array[A], lambda (Integer) :: A) :: Array[A] Given an array and a function from indices to values, populate the array by calling the function for each index in the array. @@ -122,7 +122,7 @@ def fillArray(a, f) = fill(0, f) ; a {-- -* def takePubs[A](Integer, lambda () :: A) :: A +@def takePubs[A](Integer, lambda () :: A) :: A takePubs(n, f) calls f(), publishes the first n values published by f() (as they are published), and then @@ -141,7 +141,7 @@ def takePubs(n, f) = ) >> stop | repeat(out.get) {-- -* def withLock[A](Semaphore, lambda () :: A) :: A +@def withLock[A](Semaphore, lambda () :: A) :: A Acquire the semaphore and run the thunk, publishing all values published by the thunk. Once the thunk halts, release the semaphore.