something wrong in recursive functions inside a function
[Thread Prev] | [Thread Next]
- Subject: something wrong in recursive functions inside a function
- From: vimacs <vimacs.hacks@xxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Sat, 26 May 2018 23:13:29 +0800
- To: myrddin-dev@xxxxxxxxxxxxxx
Hi, I found some problems when using recursive functions inside a function, for example: ============================= use std var data: int[10] const findme = {x const bs = {l, r std.put("l = {}, r = {}\n", l, r) if l > r -> -1 ;; var mid: int = (l + r) / 2 std.put("data[mid] = {}\n", data[mid]) if data[mid] > x -> bs(l, mid-1) elif data[mid] < x -> bs(mid+1, r) else -> mid ;; } -> bs(0, 9) } const main = { data[0] = 1 for var i = 1; i < 10; i++ data[i] = data[i-1] * 3 ;; findme(7) } =============================== This program just prints: l = 0, r = 9 data[mid] = 81 Then a segfault happens. I think that's caused by using recursive functions inside a function. So I wrote another program to test it: ========================== use std const test = {n const t0 = {i if i < n std.put("i = {}\n", i) t0(i+1) ;; } t0(0) } const main = { test(5) } ============================ This time, the above program only prints "i = 0" then exits instead of printing 5 lines. So is there something wrong with using recursive functions inside a function? Iru
Re: something wrong in recursive functions inside a function | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
Re: something wrong in recursive functions inside a function | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
- Prev by Date: Re: [PATCH] libflate (DEFLATE decoding)
- Next by Date: Re: something wrong in recursive functions inside a function
- Previous by thread: Re: [PATCH] libflate (DEFLATE decoding)
- Next by thread: Re: something wrong in recursive functions inside a function
- Index(es):