From: Aditya Mahajan <adityam@umich.edu>
To: Hans Hagen <j.hagen@xs4all.nl>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: supp-ran.lua makes code unable to work in ConTeXt
Date: Fri, 1 May 2020 23:05:22 -0400 (EDT) [thread overview]
Message-ID: <nycvar.YAK.7.77.849.2005012258460.196463@nqv-guvaxcnq> (raw)
In-Reply-To: <59d775f8-5910-d8de-7b9a-584e44cbdcd2@xs4all.nl>
[-- Attachment #1: Type: text/plain, Size: 2211 bytes --]
On Sat, 2 May 2020, Hans Hagen wrote:
> On 5/1/2020 11:38 PM, Aditya Mahajan wrote:
>> On Fri, 1 May 2020, Hans Hagen wrote:
>>
>>> On 5/1/2020 6:12 AM, Jairo A. del Rio wrote:
>>>> I've adapted the following code to make mazes in LuaLaTeX and ConTeXt:
>>>> https://www.rosettacode.org/wiki/Maze_generation#Lua
>>>>
>>>> I defined a modified version to make content visible to TeX and I saved
>>>> in a file named maze.lua:
>>>>
>>>> function make_maze_tex(w, h, m)
>>>> w = w or 16
>>>> h = h or 8
>>>>
>>>> local map = initialize_grid(w*2+1, h*2+1)
>>>>
>>>> function walk(x, y)
>>>> map[y][x] = false
>>>>
>>>> local d = { 1, 2, 3, 4 }
>>>> shuffle(d)
>>>> for i, dirnum in ipairs(d) do
>>>> local xx = x + dirs[dirnum].x
>>>> local yy = y + dirs[dirnum].y
>>>> if map[yy] and map[yy][xx] then
>>>> map[avg(y, yy)][avg(x, xx)] = false
>>>> walk(xx, yy)
>>>> end
>>>> end
>>>> end
>>>>
>>>> walk(math.random(1, w)*2, math.random(1, h)*2)
>>>>
>>>> ...ext/tex/texmf-context/tex/context/base/mkiv/supp-ran.lua:30: C stack
>>>> overflow Why does it happen? I guess it has something to do with
>>>> math.randomseed, but I don't know how to avoid this error message.
>>> no, it's just lua running out of stack space so it depends on the binary
>>> (and als the initial random value)
>>
>> But why is it running out of stack? Isn't the walk function tail
>> recursive, in which case it should not cause a stack overflow
>> (https://www.lua.org/pil/6.3.html).
> not really tail recursive: that is only true when it's the last action and
> return is used and it nests very deep
>
> function foo(...)
> ...
> return foo(...)
> end
>
> versus
>
> function foo(...)
> ...
> if something then
> foo(...)
> end
> end
Thanks for the clarification.
If you or anyone else is going to play around with generating mazes,
definitely take a look at http://www.mazesforprogrammers.com/
and the live demos here:
https://weblog.jamisbuck.org/2011/2/7/maze-generation-algorithm-recap
Aditya
[-- Attachment #2: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2020-05-02 3:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-01 4:12 Jairo A. del Rio
2020-05-01 13:21 ` Hans Hagen
2020-05-01 21:38 ` Aditya Mahajan
2020-05-01 22:25 ` Hans Hagen
2020-05-02 3:05 ` Aditya Mahajan [this message]
2020-05-02 3:17 ` Aditya Mahajan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nycvar.YAK.7.77.849.2005012258460.196463@nqv-guvaxcnq \
--to=adityam@umich.edu \
--cc=j.hagen@xs4all.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).