[Joypy-announce] joypy/Joypy: 3 new changesets

Back to archive index
scmno****@osdn***** scmno****@osdn*****
Mon Jul 22 00:32:48 JST 2019


changeset 029a7b8c618a in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=029a7b8c618a
user: Simon Forman <sform****@hushm*****>
date: Sat Jul 20 19:34:56 2019 -0700
description: Remove cuts from branch combinator.
changeset 101d507003b8 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=101d507003b8
user: Simon Forman <sform****@hushm*****>
date: Sun Jul 21 07:32:20 2019 -0700
description: Tiny edits.  Almost nothing.
changeset 8825021cd713 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=8825021cd713
user: Simon Forman <sform****@hushm*****>
date: Sun Jul 21 08:28:56 2019 -0700
description: Implement map combinator.

diffstat:

 joy/library.py |   2 +-
 thun/defs.txt  |   5 ++++-
 thun/thun.pl   |  33 +++++++++++++++++++++++++++++++--
 3 files changed, 36 insertions(+), 4 deletions(-)

diffs (87 lines):

diff -r f2d71c5ad139 -r 8825021cd713 joy/library.py
--- a/joy/library.py	Sat Jul 20 19:26:11 2019 -0700
+++ b/joy/library.py	Sun Jul 21 08:28:56 2019 -0700
@@ -1069,7 +1069,7 @@
 def map_(S, expression, dictionary):
   '''
   Run the quoted program on TOS on the items in the list under it, push a
-  new list with the results (in place of the program and original list.
+  new list with the results in place of the program and original list.
   '''
 #  (quote, (aggregate, stack)) = S
 #  results = list_to_stack([
diff -r f2d71c5ad139 -r 8825021cd713 thun/defs.txt
--- a/thun/defs.txt	Sat Jul 20 19:26:11 2019 -0700
+++ b/thun/defs.txt	Sun Jul 21 08:28:56 2019 -0700
@@ -1,9 +1,11 @@
 -- == 1 -
+? == dup bool
 ++ == 1 +
-?  == dup bool
 anamorphism == [pop []] swap [dip swons] genrec
 app1 == grba infrst
 app2 == [grba swap grba swap] dip [infrst] cons ii
+app3 == 3 appN
+appN == [grabN] cons dip map disenstacken
 at == drop first
 average == [sum 1.0 *] [size] cleave /
 b == [i] dip i
@@ -23,6 +25,7 @@
 fork == [i] app2
 fourth == rest third
 gcd == true [tuck mod dup 0 >] loop pop
+grabN == [] swap [cons] times
 grba == [stack popd] dip
 hypot == [sqr] ii + sqrt
 ifte == [nullary] dipd swap branch
diff -r f2d71c5ad139 -r 8825021cd713 thun/thun.pl
--- a/thun/thun.pl	Sat Jul 20 19:26:11 2019 -0700
+++ b/thun/thun.pl	Sun Jul 21 08:28:56 2019 -0700
@@ -214,9 +214,10 @@
 
 combo(dupdip, [P, X|S], [X|S], Ei, Eo) :- append(P, [X|Ei], Eo).
 
-combo(branch, [T, _,  true|S], S, Ei, Eo) :- !, append(T, Ei, Eo).
-combo(branch, [_, F, false|S], S, Ei, Eo) :- !, append(F, Ei, Eo).
+combo(branch, [T, _,  true|S], S, Ei, Eo) :- append(T, Ei, Eo).
+combo(branch, [_, F, false|S], S, Ei, Eo) :- append(F, Ei, Eo).
 combo(branch, [T, F,  Expr|S], S, Ei, Eo) :-
+    \+ Expr = true, \+ Expr = false,
     catch(  % Try Expr and do one or the other,
         (Expr -> append(T, Ei, Eo) ; append(F, Ei, Eo)),
         _,  % If Expr don't grok, try both branches.
@@ -241,6 +242,34 @@
     Quoted = [If, Then, R0, R1, genrec],
     append(R0, [Quoted|R1], Else).
 
+/*
+This is a crude but servicable implementation of map combinator.
+Obviously it would be nice to take advantage of the implied parallelism.
+Instead the quoted program, stack, and each term in the arg list are
+transformed to a simple Joy expression that runs the program on a prepared
+stack.  These expressions are collected in a list and the whole thing is
+evaluated with infra on an empty list, so the result is the mapped list.
+
+The chief advantage of doing it this way (as opposed to using Prolog's map)
+is that the whole state remains in the continuation expression.
+*/
+
+combo(map, [_,   []|S],         [[]|S], E,        E ) :- !.
+combo(map, [P, List|S], [Mapped, []|S], E, [infra|E]) :-
+    prepare_mapping(P, S, List, Mapped).
+
+% Set up a program for each term in ListIn
+%
+%     [term S] [P] infrst
+%
+% prepare_mapping(P, S, ListIn, ListOut).
+
+prepare_mapping(P, S, In, Out) :- prepare_mapping(P, S, In, [], Out).
+
+prepare_mapping(    _, _,     [],                   Out,  Out) :- !.
+prepare_mapping(    P, S, [T|In],                   Acc,  Out) :-
+    prepare_mapping(P, S,    In,  [[T|S], P, infrst|Acc], Out).
+
 
 /*
 Compiler



More information about the Joypy-announce mailing list
Back to archive index