Re: [NTG-context] integer displayed as .0 float in Lua-5.3

2018-08-11 Thread Alan Braslau
On Sat, 11 Aug 2018 11:29:41 +0200
Pablo Rodriguez  wrote:

> On 08/09/2018 10:16 PM, Alan Braslau wrote:
> > On Thu, 9 Aug 2018 22:00:48 +0200
> > Pablo Rodriguez  wrote:
> >   
> >> I guess that backwards compatibility should be important here, but I
> >> hope there are stronger reasons for breaking it.  
> > 
> > tonumber() provides backwards compatibility. And the recommendation
> > to use it was in the third edition (of the lua book), if not before,
> > referring to 5.2.  
> 
> I realize that the fault is mine, but with backwards compatibility I
> meant that the same operation (10 + "10") gives different results with
> different Lua versions.
> 
> Pablo

"Bad" coding can be expected to give unpredictable results.

The creators of lua thought that automatic string conversion would be useful 
(and I believe that they got this feature from "awk", which itself may have 
gotten this from some previous scripting language). But they learned that 
automatic string conversion often creates more problems than it solves, so they 
recommend using explicit conversion through tonumber().

Lua is a very beautiful and powerful language, and it gives me surprises all of 
the time. Much of what Hans does I like to call "lua magic" meaning that I 
sort-of understand it but am impressed each time. Does this make lua a poor 
(problematic) scripting language? I think like all powerful tools, one must 
take care in their use.

Alan
___
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
___

Re: [NTG-context] integer displayed as .0 float in Lua-5.3

2018-08-11 Thread Hans Åberg

> On 11 Aug 2018, at 11:33, Pablo Rodriguez  wrote:
> 
> On 08/09/2018 10:20 PM, Hans Åberg wrote:
>>> On 9 Aug 2018, at 21:20, Pablo Rodriguez wrote:
>>> [...]
>>> My background is in humanities and I don’t understand the exponent for
>>> being a float ("10²" contains an exponent
>>> [https://www.m-w.com/dictionary/exponent], but I would say is an integer
>>> in all possible worlds [or all the worlds I know ]).
>> 
>> It may refer to a floating point number syntax as in C++ [1], where the
>> three cases top there say that there must be a point '.' preceded or
>> followed by at least one digit, or at least one digit followed by an
>> exponent starting with 'e' or 'E'.
> 
> Many thanks for your explanation, Hans.

You are welcome.

> I thought there should be some kind of restriction when referring to the
> exponent, but this is why technical explanations aren’t always very
> clear. I mean, they have too many restrictions attached to them.

The C++ description allows for fast reading with just one lookahead character 
at a time, which is was important in C when it appeared in 1972 on the not so 
powerful computers of the day.

Then roundoff may make floating point numbers look like integers even they are 
not. For example, 1.0 could be 0. or 1.001.

So don't check floating numbers for equality, instead use say abs(x - y) < a 
for some small number a.

When adding exact integers and inexact floating point numbers, it is easiest to 
always make that inexact numbers, as exactness cannot always be guaranteed.


___
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
___

Re: [NTG-context] integer displayed as .0 float in Lua-5.3

2018-08-11 Thread Pablo Rodriguez
On 08/09/2018 10:25 PM, Hans Hagen wrote:
> In addition to what others already explained, you should not depend on 
> features that are implementation dependent or might disappear.

Many thanks for your detailed explanation, Hans.

I had no idea that the automatic conversion from string to number where
so dependent on the Lua version.

> That said 
> ...
> 
> \startTEXpage[offset=1em]
> \ctxlua{context([[\lastpage]])}.
> \stopTEXpage
> 
> Why do you convert \lastpage to a string using [[\lastpage]] which will 
> use the string to number conversion?

Well, I must confess that this is a new knowledge to me.

I thought that "[[ ]]" was the form to escape what I think it is the
escape character in Lua.

How I came to that assumption? Probably because I tried to add a raw
command to \ctxlua or inside a \startlua...\stoplua.

> You can just do:
> 
> \startTEXpage[offset=1em]
> \ctxlua{context(\lastpage + 1)}.
> \stopTEXpage

From this sample, I understand that "\" doesn’t need to be escaped
inside context(), does it?

> or if you really want to [[ ]]
> 
> \startTEXpage[offset=1em]
> \the\numexpr\ctxlua{context([[lastpage]] + 1)}\relax .
> \stopTEXpage
> 
> endless possibities here.

I don’t need "[[ ]]", I only thought I needed them.

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___
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
___

Re: [NTG-context] integer displayed as .0 float in Lua-5.3

2018-08-11 Thread Pablo Rodriguez
On 08/09/2018 10:20 PM, Hans Åberg wrote:
>> On 9 Aug 2018, at 21:20, Pablo Rodriguez wrote:
>> [...]
>> My background is in humanities and I don’t understand the exponent for
>> being a float ("10²" contains an exponent
>> [https://www.m-w.com/dictionary/exponent], but I would say is an integer
>> in all possible worlds [or all the worlds I know ]).
> 
> It may refer to a floating point number syntax as in C++ [1], where the
> three cases top there say that there must be a point '.' preceded or
> followed by at least one digit, or at least one digit followed by an
> exponent starting with 'e' or 'E'.

Many thanks for your explanation, Hans.

I thought there should be some kind of restriction when referring to the
exponent, but this is why technical explanations aren’t always very
clear. I mean, they have too many restrictions attached to them.

Pablo
-- 
http://www.ousia.tk
___
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
___

Re: [NTG-context] integer displayed as .0 float in Lua-5.3

2018-08-11 Thread Pablo Rodriguez
On 08/09/2018 10:16 PM, Alan Braslau wrote:
> On Thu, 9 Aug 2018 22:00:48 +0200
> Pablo Rodriguez  wrote:
> 
>> I guess that backwards compatibility should be important here, but I
>> hope there are stronger reasons for breaking it.
> 
> tonumber() provides backwards compatibility. And the recommendation
> to use it was in the third edition (of the lua book), if not before,
> referring to 5.2.

I realize that the fault is mine, but with backwards compatibility I
meant that the same operation (10 + "10") gives different results with
different Lua versions.

Pablo
-- 
http://www.ousia.tk
___
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
___