Skip to content

Commit 5219cdd

Browse files
committed
start improving ++
1 parent 585f546 commit 5219cdd

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

TODO

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,39 @@
33
print
44
++
55

6-
both seemt to be strict, so eg. "join_sep ", " (map print primes)" never
7-
returns, "print primes" never returns
6+
try:
87

9-
- finish new test_snip.def
8+
join_sep ", " [1..]
9+
print primes
10+
11+
neither ever prints anything, even in the GUI
12+
13+
- ++ implementation
14+
15+
LHS is MANAGEDSTRING
16+
17+
build a list of the right length, set last node to be RHS
18+
(not [])
19+
20+
eval LHS to find (a:x) node
21+
22+
set out to be (a:(x ++ RHS))
23+
24+
otherwise, error
25+
26+
code now:
27+
28+
action_proc_join() calls action_proc_join_sub() for (list ++ list)
29+
30+
in turn, calls heap_list_cat()
31+
32+
that uses reduce_clone_list() to clonce the LHS, then replaces elist
33+
with RHS
34+
35+
clone_list uses reduce_map_list(), which does eg. expanding
36+
MANAGEDSTRING
37+
38+
- makeing print lazy would probably be hard
1039

1140
- add multiple definitions, finish function argument destructuring
1241

src/action.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,31 @@ static void *
812812
action_proc_join_sub(Reduce *rc, PElement *pe,
813813
PElement *a, PElement *b, PElement *out)
814814
{
815+
if (PEISMANAGEDSTRING(a)) {
816+
PElement tail;
817+
818+
// expand the static string into a list
819+
reduce_clone_list(rc, a, pe);
820+
PEPUTPE(&tail, b);
821+
}
822+
else if (PEISELIST(a)) {
823+
}
824+
else if (PEISNODE(a) && PEGETVAL(a)->type == TAG_CONS) {
825+
HeapNode *cons = PEGETVAL(a);
826+
PElement hd;
827+
PEPOINTLEFT(hn, &hd);
828+
PElement tl;
829+
PEPOINTRIGHT(hn, &tl);
830+
831+
PElement t;
832+
if (!heap_list_add(rc->heap, &tl, &t))
833+
reduce_throw(rc);
834+
PEPUTP(&t,
835+
}
836+
else
837+
g_assert(FALSE);
838+
839+
815840
if (!heap_list_cat(rc, a, b, pe))
816841
return a;
817842

0 commit comments

Comments
 (0)