ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* new lmtx upload
@ 2021-07-27 17:49 Hans Hagen via ntg-context
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Hagen via ntg-context @ 2021-07-27 17:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

Hi,

I uploaded a new version that mostly concerns documentation files 
(checking them for lmtx and so). I (partly) updated the primitives 
manual (for hans vd meer) and added followingup-expressions (for pablo).

The expressions stuff (was already in previous uploads) is a side effect 
of finalizing some luametatex code. Part of it had been there in 
commented form as I had not yet made up my mind about how much is 
needed. In the end I decided to *not* integrate it in the \numexpr an 
d\dimexpr primitives because of potential compatibility issues (although 
that is unlikely given the way we use them in the core, I don't know to 
what extend users use these primitives). The long ago - one of the first 
things in luametatex - introtroduced integer division : probably went 
unnoticed (of course not by ws) which is an indication that this 
extension has been is rather safe.

Anyway, more about expressions can be found in the mentioned documents. 
Think of (one can of course also use the usual tex variables):

\starttext

\the\dimexpression 2 * 10pt + 2pt \relax

\the\dimexpression 2 * 10pt > 2pt \relax

\number\dimexpression 2 * 10pt + 2pt \relax

\number\dimexpression 2 * 10pt > 2pt \relax

\ifboolean\dimexpression 2 * 10pt > 2pt \relax yes \else nop \fi

\ifboolean\dimexpression 2 * 10sp > 2pt \relax yes \else nop \fi

\ifdimexpression 2 * 10pt > 2pt \relax yes \else nop \fi

\ifdimexpression 2 * 10sp > 2pt \relax yes \else nop \fi

% alias \ifexpression :

\ifnumexpression (2 * 10) + (3 << 4) > (4 & 5)  \relax yes \else no \fi

\stoptext

Performance wise it is comparable to \dimexpr and \numexpr (these are a 
bit faster in luametatex than in luatex), the final \relax is mandate 
(so no lookahead side effects), and these don't suffer from some of the 
somewhat weird properties of their ancestors. The main difference is 
that they support comparison and bitwise operators. I can add more but 
it probably doesn't make sense. With

\tracingexpressions1 \tracingonline1

you get info like this:

1:4: {dimenexpression rpn: 2 655360 * 131072 +}
1:4: {dimenexpression rpn: 2 655360 * 131072 >}
1:4: {dimenexpression rpn: 2 655360 * 131072 +}
1:4: {dimenexpression rpn: 2 655360 * 131072 >}
1:4: {dimenexpression rpn: 2 655360 * 131072 >}
1:4: {dimenexpression rpn: 2 2 * 131072 >}
1:4: {dimenexpression rpn: 2 655360 * 131072 >}
1:4: {dimenexpression rpn: 2 2 * 131072 >}
1:4: {numexpression rpn: 2 10 * 3 4 << + 4 5 band >}

Of course (maybe for sure) there can be bugs but then, only a few will 
ever use this (I bet hvdm is one of them, as he also uses the other new 
\if* features).

Other hidden 'pearls' (bachotex speak) will be revealed in due time,

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* new lmtx upload
@ 2021-07-06 17:10 Hans Hagen
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2021-07-06 17:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

I upgrsded lmtx. A few small things (emntioned already) at the tex end 
but Alan and I are now in metafun mode.

I (finally) adpated lmtx to delegated mplib logging, so

\startMPcode{doublefun}
     tracingall ; fill fullcircle scaled 3cm withcolor "darkmagenta" ;
\stopMPcode

should work. Just in case someone keeps an eye on the metafun code and 
wonders what 'records' are, here is an example:

\starttext

\startMPcode

     record FooA ; interim FooA := newrecord [
         name = "FooA"
         index = 123
     ] ;

     record FooB ; interim FooB := newrecord [
         name = "FooB"
         index = 456
     ] ;

     record FooC ; interim FooC := newrecord [
         name  = "FooC"
         index = 789,
         crap  = [
             more = "MORE"
         ]
     ] ;

     draw textext(getrecord(FooA).name)      rotated -45 withcolor 
"darkred"   ;
     draw textext(getrecord(FooB).name)      rotated   0 withcolor 
"darkgreen" ;
     draw textext(getrecord(FooC).name)      rotated  45 withcolor 
"darkblue"  ;
     draw textext(getrecord(FooC).crap.more) rotated  90 withcolor 
"darkgray"  ;

     begingroup;

         interim FooC := newrecord [
             name  = "FooC"
             index = 789,
             crap  = [
                 more = "NESTED 1"
             ]
         ] ;

         draw textext(getrecord(FooC).crap.more) shifted (0,-1cm) 
withcolor "darkgray" ;
         draw textext(FooC) shifted (2cm,-1cm) withcolor "darkgray" ;

         begingroup;

             interim FooC := newrecord [
                 crap  = [
                     more = "NESTED 2"
                 ]
             ] ;

             draw textext(getrecord(FooC).index) shifted (4cm,-2cm) 
withcolor "darkgray" ;
             draw textext(getrecord(FooC).crap.more) shifted (0,-2cm) 
withcolor "darkgray" ;
             draw textext(FooC) shifted (2cm,-2cm) withcolor "darkgray"  ;

         endgroup;

     endgroup;

     draw textext(getrecord(FooC).crap.more) shifted (0,-3cm) withcolor 
"darkgray" ;
     draw textext(FooC) shifted (2cm,-3cm) withcolor "darkgray"  ;

     record FooD ; interim FooD := newrecord [
         name = "FooD"
         list = { 11, 22, 33, 44 }
     ] ;

     for i=1 upto getrecord FooD.list[] :
         draw textext(getrecord(FooD).list[i]) shifted (i*cm,-5cm) 
withcolor "darkgray" ;
     endfor ;
     for i=1 upto getrecord FooD.#list :
         draw textext(getrecord(FooD).list[i]) shifted (5cm+i*cm,-5cm) 
withcolor "darkred" ;
     endfor ;

     numeric v ;
     for i=1 upto 10000 :
         v := 0 ;
         for j=1 upto 4 :
             v := v + getrecord FooD.list[j] ;
         endfor ;
     endfor ;
     draw textext(v) shifted (12cm,-5cm) withcolor "darkgray"  ;

     interim FooD := setrecord [
         name = "FooD"
         tsil = { 44, 33, 22, 11 }
     ] ;

     for i=1 upto getrecord FooD.#list :
         draw textext(getrecord FooD.list[i]) shifted (5cm+i*cm,-6cm) 
withcolor "darkgreen" ;
     endfor ;
     for i=1 upto getrecord FooD.#tsil :
         draw textext(getrecord FooD.tsil[i]) shifted (5cm+i*cm,-7cm) 
withcolor "darkgray" ;
     endfor ;

     tracingall ;

     draw textext(getrecord FooD.list[2]) shifted (5cm,-8cm) withcolor 
"darkmagenta" ;

\stopMPcode

\startluacode
     inspect(metapost.getrecord("FooA"))
     inspect(metapost.getrecord("FooB"))
     inspect(metapost.getrecord("FooC"))
     inspect(metapost.getrecord("FooD"))
\stopluacode

\stoptext

So, one can store structured data at the mp end, use it there, and 
access it also from lua (after all it's done in lua). It honors metapost 
grouping (which is what interim does with internals, and records use 
metapost internals as reference).

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* new lmtx upload
@ 2020-05-12 14:35 Hans Hagen
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2020-05-12 14:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

The tex engine has at most 65K dimen and count registers and these can 
be local and global (although mixing these two models for the same 
variable can be inefficient).

Anyway, in the current upload there is a mechanism for using way more 
variables, global ones, that are managed by lua:

\luadimen test 100pt

\scratchdimen = .25 \luadimen test

\the\scratchdimen

\the\luadimen test

So, they act as normal dimensions and counters wrt assignment and 
serialization and such. There are also floats and booleans (in addition 
to integers and cardinals).

Then, as another experiment, there are one/two dimensional arrays of 
variables. Think of:

\newarray name whatever type integer nx 100 ny 500

\arrayvalue whatever 20 30 1024

\the\arrayvalue whatever 10 30

\the\arrayvalue whatever 20 30

\the\arrayvalue whatever 30 30

Some more info can be found in the last chapoter of the evenmore.pdf 
document. The question is: do we need this, and if so, do we need more 
of that. It's a bit chicken-egg case: we can have lua and can pipe back 
to tex, and we can stay at the tex end.

This is a lmtx only feature. Just for the record: these are macros, not 
primitives, but they are rather efficient and have hardly any overhead.

The floats can be in 1.23 format, 1.23e45 format and also in 0x12p34 
format, while integers can be in 123 format and 0x123 format; the hex 
float format is lua's way of being roundtrip.

Hopefully there are no side effects.

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-27 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 17:49 new lmtx upload Hans Hagen via ntg-context
  -- strict thread matches above, loose matches on Subject: below --
2021-07-06 17:10 Hans Hagen
2020-05-12 14:35 Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).