i'd like to make a small presentation for friends about
context.
Why do we use lua and not python or perl or...
Where can i find the features for lua for this job?
Kind regards,
--
Jonas Stein
2010/12/17 Jonas Stein
Why do we use lua and not python or perl or... Where can i find the features for lua for this job?
RTFAQ: http://www.luatex.org/faq.html HTH. HAND.
2010/12/17 Jonas Stein
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or...
you can. google for “luatex lunatic”. you’ll have to build a little module defining the macros you use, though. (like \ctxpython, \directpython and so on) Where can i find the features for lua for this job?
Kind regards,
-- Jonas Stein
On 17-12-2010 11:35, Philipp A. wrote:
2010/12/17 Jonas Stein
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or...
you can. google for “luatex lunatic”. you’ll have to build a little module defining the macros you use, though. (like \ctxpython, \directpython and so on)
Where can i find the features for lua for this job?
In what sense? Context core code will never use \ctxpython, \ctxruby, \ctxperl, so it will be module specific as one cannot depend on libraries being on the system, at least not before luatex is stabelized. Btw, I'm not sure if Luigi made a module for it (if he still uses python at all). Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Fri, Dec 17, 2010 at 11:51 PM, Hans Hagen
On 17-12-2010 11:35, Philipp A. wrote:
2010/12/17 Jonas Stein
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or...
you can. google for “luatex lunatic”. you’ll have to build a little module defining the macros you use, though. (like \ctxpython, \directpython and so on)
Where can i find the features for lua for this job?
In what sense? Context core code will never use \ctxpython, \ctxruby, \ctxperl, so it will be module specific as one cannot depend on libraries being on the system, at least not before luatex is stabelized. Btw, I'm not sure if Luigi made a module for it no ( but can be interesting ) (if he still uses python at all). yes, for plone
-- luigi
On 17-12-2010 4:20, Jonas Stein wrote:
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or... Where can i find the features for lua for this job?
you can find arguments in presentations and articles and mk.pdf - nice language (pascal like, nu obscure $characters, tolerant spacing) - easy to learn and no complex concepts - good manual that covers all - mature when we started using it - small footprint and no truckload of libs to carry along (packaging tex is already enough work) - pretty fast and efficient - no feature creep, proper academic research project, tightly managed - it fits tex pretty well - designed with embedding in mind - most of all: we like it (I first ran into lua when I was playing with scite's extension mechanism and immediately thought of how nice it would be to have it in tex. Hartmut made the first variant that gave access to registers and provided printing to tex, then Taco stepped in and fundamental opening up started etc etc etc) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2010-12-17 <16:20:31>, Jonas Stein wrote:
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or... Where can i find the features for lua for this job?
After all those arguments in favor of Lua the only thing I can add are valid reasons against using python for embedding: http://twistedmatrix.com/users/glyph/rant/extendit.html and concerning perl ;) http://lua-users.org/lists/lua-l/2010-02/msg00934.html Regards, Philipp
Kind regards,
-- Jonas Stein
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
On 18-12-2010 12:27, Philipp Gesang wrote:
On 2010-12-17<16:20:31>, Jonas Stein wrote:
i'd like to make a small presentation for friends about context. Why do we use lua and not python or perl or... Where can i find the features for lua for this job?
After all those arguments in favor of Lua the only thing I can add are valid reasons against using python for embedding: http://twistedmatrix.com/users/glyph/rant/extendit.html and concerning perl ;) http://lua-users.org/lists/lua-l/2010-02/msg00934.html
Ah .. the extending vs the embedding debate ... well, an argument could have been that we don't want to extend python -) I've only used Pascal, Modula2, Perl (after all that compiling and linking I loved the scripting aspect but the language ... well ...), Ruby (brought me back happy Modula memories but it got so huge and had incompatible updates but is still my second choice), but I feel quite happy with Lua now. Anyhow, I don't like languages that need religious arguments to become popular. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
hans, some of the things you said are a bit unclear to me:
2010/12/18 Hans Hagen
Ah .. the extending vs the embedding debate ... well, an argument could have been that we don't want to extend python -)
see last paragraphs. I've only used Pascal, Modula2, Perl (after all that compiling and linking I
loved the scripting aspect but the language ... well ...), Ruby (brought me back happy Modula memories but it got so huge and had incompatible updates but is still my second choice), but I feel quite happy with Lua now.
give python a try. i love it because it has the writability of perl without (de)referencing and funny symbols, and a class system like java/c++/… (no prototyping and stuff) well, i just like it. and since i don’t know lua (well, that’s not exactly true, but i can’t write a normal sized script without looking things up), and tend to do things like i would do them in other languages i know. e.g.: how do you loop elegantly over table values? “for k,v in pairs(t) do print(v) end” creates a throwaway variable k, which doesn’t seem right. some things are totally counter-intuitive for me like tables beginning with index 1, and so on. so i guess it’s natural that i would like to use a scripting language i know and like, like python. Anyhow, I don't like languages that need religious arguments to become
popular.
like… which one? i only know of the tabs vs. spaces and vim vs. emacs religious wars. i can’t remember of any languages being subdued to that. or are you talking about lua having been invented at a catholic university and thus being a product of a sect somehow? Hans
what i want to show you is krosshttp://en.wikipedia.org/wiki/Kross_%28KDE%29 . kross is the project for bringing consistent scripting to KDE, and it is just awesome, since it allows you to write stuff in the scripting language of your choice. my dream for luatex/context would be a built-in lua interpreter (because lua is so fucking small) and optional modules for other, heavier, scripting languages (perl, ruby), which you don’t have to install. i don’t care if python is embedded or extended, i just want to write \directpython{for num in [9,2,4,8]: ctx.print(num**3)} (or sth. like that) but don’t get me wrong, i love context and luatext, i just like other languages better than lua (you weren’t content with latex and created context, so this shouldn’t be alien to you)
On Sat, 18 Dec 2010, Philipp A. wrote:
my dream for luatex/context would be a built-in lua interpreter (because lua is so fucking small) and optional modules for other, heavier, scripting languages (perl, ruby), which you don’t have to install. i don’t care if python is embedded or extended, i just want to write \directpython{for num in [9,2,4,8]: ctx.print(num**3)} (or sth. like that)
luatex is more than lua (or any prog/scripting language) embedded in tex; it is a programming language with acess to tex's internals. For example, you can find the dimension of each node in a vlist and use a different line-breaking algorithm or tweak the node list after line breaking is done (something like this is done in arabic line-breaking). If you do not want easy access to tex's internals, embedding/extending tex is relatively easy: see for example perltex. Whether the binary of the prog language is embedded in the tex binary, or in the wrapper script for calling tex is immaterial. On the other hand, if you want acess to tex's internals, you can either code it for a specific language (like luatex does), or provide an API interface to the internals. My understanding is that given the complexity of the tex codebase, the latter was more too much effort for too little gain. After all, python vs lua is a minor difference, compared to the programing abilities of TeX. Aditya
On 2010-12-18 <01:50:29>, Philipp A. wrote: <snip lines="some"/>
well, i just like it. and since i don’t know lua (well, that’s not exactly true, but i can’t write a normal sized script without looking things up), and tend to do things like i would do them in other languages i know. e.g.: how do you loop elegantly over table values? “for k,v in pairs(t) do print(v) end” creates a throwaway variable k, which doesn’t seem right. some things
Depending on whether you want to access the non-hashed content as well you might want to use the “next” iterator instead as it’s slightly faster (according to my tests, that is). You won’t get around the local variable, though; I have no clue and no time to check if it’s even technically feasible to iterate a hash table without accessing the hashes.
are totally counter-intuitive for me like tables beginning with index 1, and so on.
Feels natural after some time, I guarantee. And you’ll never look the same way at a fencepost again … What you’ll miss most is all the nice shortcuts and syntactic sugar like “setdefault(k,[]).append(v)” (two lines in Lua) and the lazy handling of arrays, strings &c. as sequences that can be iterated over like it was all the same, and probably the error handling. Nothing you can’t live without.
Anyhow, I don't like languages that need religious arguments to become popular.
or are you talking about lua having been invented at a catholic university and thus being a product of a sect somehow?
Never looked at it that way. There should be a “fun facts” section on the wiki to list all the confusing mysteries surrounding context. Regards, Philipp PS:
kross is the project for bringing consistent scripting to KDE, and it is just awesome, since it allows you to write stuff in the scripting language of your choice.
Apart from being OT, you can always switch to a window manager that uses your favorite scripting language instead -- mine has Lua inside which is a lot cleaner than doing configuration in e.g. bash or something. -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
On 18-12-2010 12:03, Philipp Gesang wrote:
On 2010-12-18<01:50:29>, Philipp A. wrote:
<snip lines="some"/>
well, i just like it. and since i don’t know lua (well, that’s not exactly true, but i can’t write a normal sized script without looking things up), and tend to do things like i would do them in other languages i know. e.g.: how do you loop elegantly over table values? “for k,v in pairs(t) do print(v) end” creates a throwaway variable k, which doesn’t seem right. some things
Depending on whether you want to access the non-hashed content as well you might want to use the “next” iterator instead as it’s slightly faster (according to my tests, that is). You won’t get around the local variable, though; I have no clue and no time to check if it’s even technically feasible to iterate a hash table without accessing the hashes.
indeed, for k, v in next, sometable do ... is faster as it saves one function call (i.e. pairs returning the next, table) for indexed iteration using for i=1,n do ... is much faster than ipairs as it involves no function calls
are totally counter-intuitive for me like tables beginning with index 1, and so on.
Feels natural after some time, I guarantee. And you’ll never look the same way at a fencepost again …
indeed, I also like the start at 1 very much, as you say .. natural
What you’ll miss most is all the nice shortcuts and syntactic sugar like “setdefault(k,[]).append(v)” (two lines in Lua) and the lazy handling of arrays, strings&c. as sequences that can be iterated over like it was all the same, and probably the error handling. Nothing you can’t live without.
and often you can roll out your own without carying the truckload of (mostly soon forgotten) lib code
Anyhow, I don't like languages that need religious arguments to become popular.
or are you talking about lua having been invented at a catholic university and thus being a product of a sect somehow?
Never looked at it that way. There should be a “fun facts” section on the wiki to list all the confusing mysteries surrounding context.
I was refering to python related religious (with the programming language being the gospel) discussions, so far I never ran into a lua one. All those 'one should use this language over that' or 'this operating system over that one' are wasted on me as languages come and go, as do operating systems and related concepts. Pointless discussions when seen over a 1000 year period of time. Printing used to be done using wooden blocks and that was high end and the best at some point, then came lead (too poisonous now), then film (short fashion), now ...
Regards, Philipp
PS:
kross is the project for bringing consistent scripting to KDE, and it is just awesome, since it allows you to write stuff in the scripting language of your choice.
like .net
Apart from being OT, you can always switch to a window manager that uses your favorite scripting language instead -- mine has Lua inside which is a lot cleaner than doing configuration in e.g. bash or something.
sure, and performance seldom is an issue I guess on todays machines. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2010-12-18 <12:35:38>, Hans Hagen wrote:
On 18-12-2010 12:03, Philipp Gesang wrote:
Depending on whether you want to access the non-hashed content as well you might want to use the “next” iterator instead as it’s slightly faster (according to my tests, that is). You won’t get around the local variable, though; I have no clue and no time to check if it’s even technically feasible to iterate a hash table without accessing the hashes.
indeed, for k, v in next, sometable do ... is faster as it saves one function call (i.e. pairs returning the next, table)
for indexed iteration using for i=1,n do ... is much faster than ipairs as it involves no function calls
Well, according to a quick test using “next” with hash tables has only a *very* slight advantage (in time) over pairs. With arrays the difference to ipairs() is much higher; in mixed arrays/hashes it might turn out even higher. For tables I came up with this relation (“<” meaning less execution time than): while < for < repeat < next < ipairs where “repeat … until” and “while … do … end” check if the final index has been reached. But the difference between the three loops is rather neglegible. What always baffled me is that in the manual Roberto advertises ipairs() as the iterator of choice (at least in the v.5.0 doc). Compared to the other options using it is just, well, erratic. Regard, Philipp -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
On 18-12-2010 2:06, Philipp Gesang wrote:
What always baffled me is that in the manual Roberto advertises ipairs() as the iterator of choice (at least in the v.5.0 doc). Compared to the other options using it is just, well, erratic.
I did lots of testing (an doptimizing) in critical code but in practice one will not notice much difference in a mkiv run. Actually, I changed all pairs, ipairs as there was a temporary intention to remove them from the lua core. btw, in for i=1,#t do ... the #t is also a function call (so having many in these t[#t+1] = ... cases is also slower but again, seldom noticeable as lua in general is so fast a similar dicussion can be held for strings being hashed but again the penalty is neglectable esp if one takes into account that strings only have one instance and compare real fast (pointer comparison); in mkiv / luatex we have lots of strings (keys, identical values, etc) and it really pays off to have them hashed Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2010-12-18 <14:20:46>, Hans Hagen wrote:
On 18-12-2010 2:06, Philipp Gesang wrote:
What always baffled me is that in the manual Roberto advertises ipairs() as the iterator of choice (at least in the v.5.0 doc). Compared to the other options using it is just, well, erratic.
I did lots of testing (an doptimizing) in critical code but in practice one will not notice much difference in a mkiv run. Actually, I changed all pairs, ipairs as there was a temporary intention to remove them from the lua core.
btw, in for i=1,#t do ... the #t is also a function call (so having
My fault, I just forgot about that; with the array size stored in a local variable the “for” loop is faster than “while”, as expected.
many in these t[#t+1] = ... cases is also slower but again, seldom noticeable as lua in general is so fast
… when adding to an array the “t[#t+1] = elm” approach turns out to be still faster than table.insert() which, again, is advertised in the manual. Even python’s append() method is faster than table.insert() and that means a lot. Philipp -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
On 18-12-2010 3:17, Philipp Gesang wrote:
… when adding to an array the “t[#t+1] = elm” approach turns out to be still faster than table.insert() which, again, is advertised in the manual. Even python’s append() method is faster than table.insert() and that means a lot.
seems to be faster in upcoming 5.2 ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi, On 12/18/2010 01:50 AM, Philipp A. wrote:
like… which one? i only know of the tabs vs. spaces
The significant whitespace is why python would not have been an option for the core extension language in luatex even if it was twice as small and twice as fast as lua. Forced indentation simply does not work out well if data and program are intermixed in the same source file. Which is not saying that I don't like python, but (also taking account the other differences to lua) it is simply the wrong tool for the job.
my dream for luatex/context would be a built-in lua interpreter (because lua is so fucking small) and optional modules for other, heavier, scripting languages (perl, ruby), which you don’t have to install.
An extended version of luatex-lunatic (or some similar project) would potentially allow that. A lot of the lua functions that 'talk' to the internals are nothing more than wrappers for argument and return value grabbing, and it would be pretty easy to (re)code those bindings for any other scripting language. The remaining functions that are not trivially implemented are the ones that we need to work on before 1.0, because these are the exactly the areas where the TeX source is too messy to be easily interfaced, in any scripting language. Best wishes, Taco
On 18-12-2010 1:50, Philipp A. wrote:
but don’t get me wrong, i love context and luatext, i just like other languages better than lua (you weren’t content with latex and created context, so this shouldn’t be alien to you)
Sure, it's just that the core of context will be tex/lua only as it needs to be portable and mixing languages will not help at that level. Probably the best way to use other languages in applications of context / luatex is to do something lunatic that luigi did, the overhead of wrapping is probably neglectable. We can look into that around luatex version 1.0. For me personally the only reason to look into pyton (or ruby or perl or php or ...) would be that it's needed in a project but so far i never had such projects i.e. could choose my own languages (so it was ruby at some point and lua now). Who knows what the future brings. Hans ps. I once read about Icon as language and somehow that one also had some appeal. I never had a running environment. Smalltalk is also nice, esp the (original) books (esp the historic one), and Lisp (in relation to tex) also has some appeal. Live is too short to learn all those languages and stay fluent in them, i.e. one simply forgets a lot when usage zeros. ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sat, Dec 18, 2010 at 2:04 PM, Hans Hagen
ps. I once read about Icon as language and somehow that one also had some appeal. I never had a running environment. Smalltalk is also nice, esp the (original) books (esp the historic one), it's easy to try squeak http://www.squeak.org/
and Lisp (in relation to tex) also has some appeal. True, see http://www.nongnu.org/skribilo/ (there is also a context support) A binding to libguile should be no difficult to achieve.
Live is too short to learn all those languages and stay fluent in them, i.e. one simply forgets a lot when usage zeros. we should start to think how to to become immortal.
-- luigi
On 18-12-2010 2:18, luigi scarso wrote:
True, see http://www.nongnu.org/skribilo/ (there is also a context support) A binding to libguile should be no difficult to achieve.
ah, interesting ... we should have a sort of reference context document with some structure, itemize, tables, graphics etc and then see how it would code in different languages that way (one problem is lazy evaluation in function arguments, so it might be that lisp is the best variant). Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (8)
-
Aditya Mahajan
-
Hans Hagen
-
Jonas Stein
-
luigi scarso
-
Martin Schröder
-
Philipp A.
-
Philipp Gesang
-
Taco Hoekwater