On 2/11/2018 8:49 AM, Otared Kavian wrote:
On 10 Feb 2018, at 17:56, Hans Hagen
wrote: On 2/10/2018 4:10 PM, Otared Kavian wrote:
[…] buffers are quite efficient as they never see the file system while input reads the file each time .. both are fresh reads so they obey catcode changes (different interpretations of characters)
there might be more efficient ways for your case but without an example that's guessing
Hi Hans,
Thank you very much for your attention and your explanations about buffers.
I send below a working example showing what I wish to do: to extract from a data buffer some informations to be typeset separately according to some criteria. Maybe I am using the buffer where the data is stored inappropriately, but I can obtain what I want.
However if a sorting were necessary, then my approach would not work…. Is it possible to sort the buffer containing the data according to some key?
Think different ... see end.
Best regards: OK
%% begin setvariable-getbuffer.tex \startbuffer[talkdata] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setvariables[talk]% [speakername={Gauss}, title={Remarks on Number Theory}, time={8am}, room={B}, day={Monday}, ] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setvariables[talk]% [speakername={Ampère}, title={What is Magnetism}, time={10am}, room={A}, day={Monday}, ] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setvariables[talk]% [speakername={Dirac}, title={Quaternions and the wave equation}, time={11am}, room={B}, day={Tuesday}, ] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \stopbuffer
% we define what is to be typeset for each day \define[1]\talksofday{% \expdoif{\getvariable{talk}{day}}{#1}{% \starttabulate[|f{\bi}l|p|][before=]% \NC Speaker \EQ \getvariable{talk}{speakername} \NC\NR \NC Title \EQ \getvariable{talk}{title} \NC\NR \NC Location and Time \EQ Room \getvariable{talk}{room}, at \getvariable{talk}{time} \NC\NR \HL \stoptabulate } }
% we define what is to be typeset for each room \define[1]\talksofroom{% \expdoif{\getvariable{talk}{room}}{#1}{ \starttabulate[|f{\bi}l|p|][before=]% \NC Speaker \EQ \getvariable{talk}{speakername} \NC\NR \NC Title \EQ \getvariable{talk}{title} \NC\NR \NC Day and Time \EQ \getvariable{talk}{day}, at \getvariable{talk}{time} \NC\NR \HL \stoptabulate } }
\starttext
\starttitle[title={Monday talks}] \setvariable{talk}{set}{\talksofday{Monday}} \getbuffer[talkdata] \stoptitle \page
\starttitle[title={Tuesday talks}] \setvariable{talk}{set}{\talksofday{Tuesday}} \getbuffer[talkdata] \stoptitle \page
\starttitle[title={Talks in room B}] \setvariable{talk}{set}{\talksofroom{B}} \getbuffer[talkdata] \stoptitle
\stoptext %% end setvariable-getbuffer.tex \startluacode
-- document.speakerdata = table.load("somefile.lua") -- -- with somefile.lue: return { ... } document.speakerdata = { { speakername = "Gauss", title = "Remarks on Number Theory", time = "8am", room = "B", day = "Monday", }, { speakername = "Ampère", title = "What is Magnetism", time = "10am", room = "A", day = "Monday", }, { speakername = "Dirac", title = "Quaternions and the wave equation", time = "11am", room = "B", day = "Tuesday", }, } \stopluacode \startluacode document.talksofday = function(how) local data = document.speakerdata if how == "speakername" then local sort = { } for i=1,#data do sort[i] = data[i] end table.sort(sort,function(a,b) return a.speakername < b.speakername end) data = sort end context.starttabulate { "|f{\\bi}l|p|" } context.HL() for i=1,#data do local d = data[i] context.NC() context("Speaker") context.EQ() context(d.speakername) context.NC() context.NR() context.NC() context("Title") context.EQ() context(d.title) context.NC() context.NR() context.NC() context("Location and Time") context.EQ() context("Room %s at %s",d.room,d.time) context.NC() context.NR() context.HL() end context.stoptabulate() end \stopluacode \starttext \starttitle[title={Monday talks}] \ctxlua{document.talksofday()} \stoptitle \starttitle[title={Monday talks}] \ctxlua{document.talksofday("speakername")} \stoptitle \starttitle[title={Monday talks}] \ctxlua{document.talksofday()} \stoptitle \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------