Cosmetics in stdlib

This commit is contained in:
Dmitry Boulytchev 2020-02-20 12:43:52 +03:00
parent 7fd85f27ef
commit 5933f4c3b1
15 changed files with 105 additions and 79 deletions

View file

@ -1 +1 @@
let version = "Version 1.00, b7271d16, Tue Feb 18 14:08:39 2020 +0300"
let version = "Version 1.00, 7fd85f27, Wed Feb 19 21:21:18 2020 +0300"

View file

@ -1,8 +1,9 @@
-- Array package.
-- Arrays.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This package provides a simplistic implementation of immutable set/map/hashtable
-- data structures.
-- This unit provides a set of array-manipulation primitives. Note, some of these
-- primitives can be applied to any boxed value in Lama, not necessarily arrays
-- per se.
import List;

View file

@ -1,7 +1,7 @@
-- Collection package.
-- Collections.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This package provides a simplistic implementation of immutable set/map/hashtable
-- This unit provides a simplistic implementation of immutable set/map/hashtable
-- data structures.
import List;

View file

@ -1,66 +0,0 @@
import Ostap;
import List;
import Fun;
public fun left (f) {
fun (c, x) {
fun (y) {
f (c (x), y)
}
}
}
public fun right (f) {
fun (c, x) {
fun (y) {
c (f (x, y))
}
}
}
--- ops -> fun (x, y) {x `op` y}
fun altl (level) {
case level of
[assoc, ps] ->
local assfun = case assoc of Left -> left | Right -> right | Nona -> left esac;
case map (fun (p) {
case p of
[op, sema] -> op @ lift(assfun (sema))
esac
}, ps) of
p : ps -> foldl (infix |, p, ps)
esac
esac
}
public fun expr (ops, opnd) {
fun inner (ops) {
case ops of
{} -> fun (c) {opnd @ c}
| level : tl ->
local lops = altl (level),
next = inner (tl);
case level.fst of
Nona ->
fun this (c) {
next (id) |> fun (l) {lops |> fun (op) {next (id) @ fun (r) {c (op)(id, l)(r)}}}
| next (id) @ c
}
this
| _ ->
fun this (c) {
next (id) |> fun (l) {lops |> fun (op) {this (op (c, l))}}
| next (id) @ c
}
this
esac
esac
}
inner (ops)
}

View file

@ -1,3 +1,8 @@
-- Fun.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This unit provides some convenient function-manipulation stuff.
import Ref;
public fun id (x) {

View file

@ -1,10 +1,21 @@
-- Lazy.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- Deferred computations.
public fun makeLazy (f) {
local value, set = false;
fun () {
if set
then value
else set := true; value := f (); value
else
local c; -- need this temporary since in value := f () value would
-- create an intermediate managed pointer
set := true;
c := f ();
value := c;
c
fi
}
}

View file

@ -1,3 +1,8 @@
-- Lists.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This unit provides a set of list-manipulation primitives.
public fun singleton (x) {
x : {}
}

View file

@ -1,3 +1,9 @@
-- Ostap.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This unit provides an implementation of monadic parser combinators in CPS with
-- memoization.
import List;
import Collection;
import Ref;
@ -226,4 +232,66 @@ public fun parseString (p, s) {
acc.result
}
public fun left (f) {
fun (c, x) {
fun (y) {
f (c (x), y)
}
}
}
public fun right (f) {
fun (c, x) {
fun (y) {
c (f (x, y))
}
}
}
--- ops -> fun (x, y) {x `op` y}
fun altl (level) {
case level of
[assoc, ps] ->
local assfun = case assoc of Left -> left | Right -> right | Nona -> left esac;
case map (fun (p) {
case p of
[op, sema] -> op @ lift(assfun (sema))
esac
}, ps) of
p : ps -> foldl (infix |, p, ps)
esac
esac
}
public fun expr (ops, opnd) {
fun inner (ops) {
case ops of
{} -> fun (c) {opnd @ c}
| level : tl ->
local lops = altl (level),
next = inner (tl);
case level.fst of
Nona ->
fun this (c) {
next (id) |> fun (l) {lops |> fun (op) {next (id) @ fun (r) {c (op)(id, l)(r)}}}
| next (id) @ c
}
this
| _ ->
fun this (c) {
next (id) |> fun (l) {lops |> fun (op) {this (op (c, l))}}
| next (id) @ c
}
this
esac
esac
}
inner (ops)
}
initOstap ()

View file

@ -1,11 +1,19 @@
-- Emulation of first-class references.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- This unit provides an implementation for first-class references emulation.
-- Creates a new reference cell with contents x
public fun ref (x) {
[x]
}
-- Returns the contents of the cell x
public fun deref (x) {
x[0]
}
-- Assigns a new value y into the cell x
public infix ::= before := (x, y) {
x[0] := y
}

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
local a = token ("a"),

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
fun gen (depth) {

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
local a = token ("a"),

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
import List;

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
import List;

View file

@ -1,5 +1,4 @@
import Ostap;
import Expr;
import Fun;
import List;