Subject: mailing-list for TeXmacs Users
List archive
From : "Takama M." <address@hidden>- To: address@hidden
- Subject: Re: [TeXmacs] style sheet language value typing
- Date: Sun, 5 Aug 2018 22:56:35 +0900
I don't understand things completely, but you can do as follows.
In the scheme session, define a function
(define (bottom-elm ls)
(if (pair? ls)
(bottom-elm (list-ref ls (1- (length ls))))
ls))
then, for example
(bottom-elm '(1 2 3 (4 5) (6 7 (8 9 10)))) gives 10.
Using this function, the expression
<minus|5|<extern|(compose bottom-elm tree->stree)|<last-character|42>>>
should work with the result (i.e. 3).
So, to do all things in macro expressions,
<assign|cval|<macro|expr|<extern|(lambda (expr) (letrec ((belm (lambda
(xs) (if (pair? xs) (belm (list-ref xs (1- (length xs)))) xs)) )) (belm
(tree->stree expr))))|<arg|expr>>>>
then
<minus|5|<cval|<last-character|42>>> gives the answer.
You can also define the 'nth' macro as
<assign|nth|<macro|n|<with|d|<cval|<last-character|<arg|n>>>|
<case|<equal|<arg|d>|1>|<arg|n><rsup|st>|<equal|<arg|d>|2>|<arg|n><rsup|nd>|<equal|<value|d>|3>|
<arg|n><rsup|rd>|<arg|n><rsup|th>>>>>
--
Takama M.
On 2018年08月04日 13:40, Kyle Andrews wrote:
Dear TeXmacs users,
I am trying to learn the style sheet language by implementing a simple
macro called nth. The goal of this macro is to transform 1 and 1st, 2 into
2nd, 3 into 3rd, and 4 into 4th, and so on. The code is shown below.
<assign|last-character|<macro|expr|<with|n|<length|<arg|expr>>|<range|<arg|expr>|<minus|<value|n>|1>|<value|n>>>>>
<assign|nth|<macro|n|<with|d|<last-character|<arg|n>>|<case|<equal|<arg|d>|1>|<arg|n><rsup|st>|<equal|<arg|d>|2>|<arg|n><rsup|nd>|<equal|<value|d>|3>|<arg|n><rsup|rd>|<arg|n><rsup|th>>>>>
It seems like it should work, but I'm missing something fundamental in my
understanding about how the style sheet macro language does value typing. I
tried taking <minus|5|<last-character|42>>, and got <error|bad plus/minus>.
When I tried to compare equality, I got false. Clearly these things are
being interpreted by the parser in a way I don't understand.
I tried searching for some documentation about this kind of thing in the
manual, but so far haven't had any luck. I would appreciate any pointers
from the community.
Best Regards,
Kyle
P.S.
Here is a nicer scheme-like representation fo the macro code:
(document
(assign "last-character"
(macro "expr"
(with "n" (length (arg "expr"))
(range (arg "expr")
(minus (value "n") "1")
(value "n")))))
(assign "nth"
(macro "n"
(with "d" (last-character (arg "n"))
(case (equal (arg "d") "1") (concat (arg "n") (rsup "st"))
(equal (arg "d") "2") (concat (arg "n") (rsup "nd"))
(equal (value "d") "3") (concat (arg "n") (rsup "rd"))
(concat (arg "n") (rsup "th")))))))
--
===============================================
高間 道秋
Tel : 075-703-4142
E-mail: address@hidden
address@hidden
===============================================
- [TeXmacs] style sheet language value typing, Kyle Andrews, 08/04/2018
- <Possible follow-up(s)>
- Re: [TeXmacs] style sheet language value typing, Takama M., 08/05/2018
- Re: [TeXmacs] style sheet language value typing, Kyle Andrews, 08/06/2018
- Re: [TeXmacs] style sheet language value typing, Kyle Andrews, 08/11/2018
- [TeXmacs] Need help for using String-replace, Bertrand BRATSCHI, 08/23/2018
- Re: [TeXmacs] style sheet language value typing, Kyle Andrews, 08/11/2018
- Re: [TeXmacs] style sheet language value typing, Kyle Andrews, 08/06/2018
Archive powered by MHonArc 2.6.19.