Skip to content

Commit 3c6d3c9

Browse files
committed
mop$ maps function to elements of expression & outputs space separated list
1 parent 18eb96f commit 3c6d3c9

10 files changed

+1720
-1762
lines changed

Changelog

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
2 May 2022
2-
map$ can now handle a non-list expression as though it were a list. For that,
3-
there is an extra argument telling on what type of operator to split the
4-
expression.
5-
E.g. map$((=.!arg) 2*a+i*b+e\Lc (=+))
2+
New built-in function mop$ iterates over terms/factors/elements and outputs a
3+
space operator separated list.
4+
E.g. mop$((=.!arg).2*a+i*b+e\Lc.(=+))
65
evaluates to 2*a e\Lc i*b
76

87
26 October 2021

doc/bracmat-table.html

+1,105-1,257
Large diffs are not rendered by default.

doc/bracmat.html

+194-195
Large diffs are not rendered by default.

doc/bracmat.pdf

-402 KB
Binary file not shown.

doc/bracmat.tex

+39-8
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ \subsection{Built-in functions}
32953295
32963296
Returns the current value of the file position indicator.
32973297
3298-
\bfun{\bc{fil\d(}\bi{file-ame}\bc,\bi{whence}\bc,\bi{offset}\bc)}
3298+
\bfun{\bc{fil\d(}\bi{file-name}\bc,\bi{whence}\bc,\bi{offset}\bc)}
32993299
33003300
Go to file position.
33013301
@@ -3646,20 +3646,51 @@ \subsection{Built-in functions}
36463646
_oct{!} 1 4 9 16
36473647
{?} ( map
36483648
_d[] ( (
3649-
= x
3650-
. !arg:?*?^%?x*?*?^!x*?
3651-
& (!arg."same exponent" !x)
3652-
| (!arg.)
3653-
)
3654-
. a*b^3*c^2 d*f^3*g^2*h*j^3 o*p
3655-
)
3649+
= x
3650+
. !arg:?*?^%?x*?*?^!x*?
3651+
& (!arg."same exponent" !x)
3652+
| (!arg.)
36563653
)
3654+
. a*b^3*c^2 d*f^3*g^2*h*j^3 o*p
3655+
)
3656+
)
36573657
_oct{!} (a*b^3*c^2.)
36583658
_oct (d*f^3*g^2*h*j^3.same exponent 3)
36593659
_oct (o*p.)
36603660
\end{ex}
36613661
3662+
\bfun{\bc{mop\d(}\bi{fnc}.\bi{expression}.(=\bi{non-leaf expression}\bc))}
3663+
\index{mop@\bc{mop}}
3664+
3665+
\verb|mop$| traverses a list-like expression element by element and outputs a space
3666+
operator separated list. For that to work, \verb|mop$| needs an extra argument that
3667+
tells which operator to use. That argument is always headed by \verb|=|, the
3668+
right hand side of which is a non-leaf expression. The top operator of that
3669+
expression is used as the separating operator.
3670+
\begin{ex}
3671+
{?} mop_d((=.!arg).aap+noot+mies.(=+))
3672+
_oct{!} aap mies noot
3673+
{?} (x=2*a+i*b+e\Lc) & mop_d((=.!arg).!x.()'($x))
3674+
_oct{!} 2*a e\Lc c i*b
3675+
_oct{!}
3676+
\end{ex}
3677+
3678+
It is possible to have a list with space operators as separating operator:
3679+
3680+
\begin{ex}
3681+
{?} mop'((=.!arg).a b c.(=x y))
3682+
_oct{!} a b c
3683+
\end{ex}
3684+
3685+
Another way to do this is to use the \verb|map$| function
3686+
3687+
\begin{ex}
3688+
{?} map'((=.!arg).a b c)
3689+
{!} a b c
3690+
\end{ex}
3691+
36623692
\bfun{\bc{mem\d}[\bc{EXT}]}
3693+
36633694
\index{mem@\bc{mem}}
36643695
36653696
\verb|mem$| produces a list of all currently existing variables,

doc/help

+64-35
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ help=
77
. varmattxt,varprotxt,progsmenu,debugtxt,debugtxt2,debugtxt3
88
. inbltmenu,alctxt,aligntxt,asctxt,utftxt,chrtxt,charset
99
. chutxt,dbgtxt,dentxt,escappattxt,lambda,morexmlps,jsntxt
10-
. divtxt,fretxt,funtxt1,funtxt3,beztxt
10+
. divtxt,fretxt,funtxt1,funtxt3,beztxt,moptxt
1111
. lsttxt1,difftxt,pattxt2,methodtxt,predvartxt
1212
. lsttxt2,lsttxt3,memtxt,modtxt,peetxt,poktxt,Bracmat-name
1313
. puttxt1,puttxt2,puttxt3,rentxt,revtxt,seltxt,simtxt,strtxt
@@ -179,39 +179,41 @@ lex lexical analysis of help file"
179179
list existing variable names
180180
22 |_mod_|
181181
remainder
182-
23 |_new_|
182+
23 |_mop_|
183+
map expression to space separated list
184+
24 |_new_|
183185
create new object as a copy of another object
184-
24 |_pee_|
186+
25 |_pee_|
185187
get value from address (peek) (low level)
186-
25 |_pok_|
188+
26 |_pok_|
187189
put value at address (poke) (low level)
188-
26 |_put_|
190+
27 |_put_|
189191
write output
190-
27 |_ren_|
192+
28 |_ren_|
191193
rename file or directory or move file
192-
28 |_rev_|
194+
29 |_rev_|
193195
string reverse
194-
29 |_rmv_|
196+
30 |_rmv_|
195197
remove file
196-
30 |_sim_|
198+
31 |_sim_|
197199
similarity between two atoms
198-
31 |_str_|
200+
32 |_str_|
199201
stringize expression into atom
200-
32 |_swi_|
202+
33 |_swi_|
201203
software interrupt (low level)
202-
33 |_sys_|
204+
34 |_sys_|
203205
command line shell
204-
34 |_tbl_|
206+
35 |_tbl_|
205207
create array, remove array/variable
206-
35 |_upp_|
208+
36 |_upp_|
207209
convert to upper case
208-
36 |_utf_|
210+
37 |_utf_|
209211
convert UTF-8 character to Unicode codepoint
210-
37 |_vap_|
212+
38 |_vap_|
211213
deconstruct a string character-wise or according to specified separator
212-
38 |_whl_|
214+
39 |_whl_|
213215
while loop
214-
39 |_x2d_|
216+
40 |_x2d_|
215217
convert hexadecimal number to decimal number x2d$BABEFACE:3133078222
216218
"
217219
, (1,seltxt)
@@ -236,23 +238,24 @@ lex lexical analysis of help file"
236238
(20,maptxt)
237239
(21,memtxt)
238240
(22,modtxt)
239-
(23,newobjecttxt)
240-
(24,peetxt)
241-
(25,poktxt)
242-
(26,puttxt1 humtxt puttxt2 puttxt3 newtxt)
243-
(27,rentxt)
244-
(28,rmvtxt)
245-
(29,revtxt)
246-
(30,simtxt)
247-
(31,strtxt)
248-
(32,switxt)
249-
(33,systxt)
250-
(34,tbltxt)
251-
(35,upptxt DOSopttxt)
252-
(36,utftxt)
253-
(37,vaptxt)
254-
(38,whltxt)
255-
(39,x2dtxt)
241+
(23,moptxt)
242+
(24,newobjecttxt)
243+
(25,peetxt)
244+
(26,poktxt)
245+
(27,puttxt1 humtxt puttxt2 puttxt3 newtxt)
246+
(28,rentxt)
247+
(29,rmvtxt)
248+
(30,revtxt)
249+
(31,simtxt)
250+
(32,strtxt)
251+
(33,switxt)
252+
(34,systxt)
253+
(35,tbltxt)
254+
(36,upptxt DOSopttxt)
255+
(37,utftxt)
256+
(38,vaptxt)
257+
(39,whltxt)
258+
(40,x2dtxt)
256259
)
257260
& ( intro
258261
= M
@@ -3665,6 +3668,32 @@ separated by the space operator.
36653668
(d*f^3*g^2*h*j^3.same exponent 3)
36663669
(o*p.)"
36673670
)
3671+
& ( moptxt
3672+
= T
3673+
, "mop$(<fnc>.<expression>.(=<non-leaf expression>))"
3674+
, "mop$ traverses a list-like expression element by element and outputs a space
3675+
operator separated list. For that to work, mop$ needs an extra argument that
3676+
tells which operator to use. That argument is always headed by |_=_|, the
3677+
right hand side of which is a non-leaf expression. The top operator of that
3678+
expression is used as the separating operator.
3679+
{?} mop$((=.!arg).aap+noot+mies.(=+))
3680+
{!} aap mies noot
3681+
{?} (x=2*a+i*b+e\Lc) & mop$((=.!arg).!x.()'($x))
3682+
{!} 2*a e\Lc i*b
3683+
{?} mop$((=.!arg)..(=*))
3684+
{!}
3685+
3686+
It is possible to have a list with space operators as separating operator:
3687+
3688+
{?} mop'((=.!arg).a b c.(=x y))
3689+
{!} a b c
3690+
3691+
Another way to do this is to use the map$ function
3692+
3693+
{?} map'((=.!arg).a b c)
3694+
{!} a b c
3695+
"
3696+
)
36683697
& ( vaptxt
36693698
= T
36703699
, "vap$(<fnc>.<string>) or vap$(<fnc>.<string>.<separator>)"

0 commit comments

Comments
 (0)