public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien MATTEI <Damien.Mattei@unice.fr>
To: Kawa mailing list <kawa@sourceware.org>
Subject: StackOverflowError in a specialized map
Date: Wed, 15 Mar 2017 15:08:00 -0000	[thread overview]
Message-ID: <201703151608.33735.Damien.Mattei@unice.fr> (raw)

Hello,

i have a custom definition of map ( https://github.com/damien-mattei/LOGIKI/blob/master/lib/map.scm at  line 392):

;; map-nil : a map version that exclude nil results
;; the same as map-with-lambdas but will exclude from the result list the '() result of function
;;
;; (map-nil + '(1 2 3) '(4 5 6)) -> '(5 7 9)
(define map-nil
  (lambda (function list1 . more-lists)
    (letrec ((some? (lambda (fct list)
		      ;; returns #f if (function x) returns #t for 
		      ;; some x in the list
		      (and (pair? list)
			   (or (fct (car list))
			       (some? fct (cdr list)))))))
      
      ;; variadic map implementation terminates
      ;; when any of the argument lists is empty.
      (let ((lists (cons list1 more-lists)))
	(if (some? null? lists)
	    '()
	    (let ((funct-result (apply function (map car lists))))
	      (if (null? funct-result)
		  (apply map-nil function (map cdr lists))
		  (cons funct-result
			(apply map-nil function (map cdr lists))))))))))

i use it in various project since many years and this times it creates a java StackOverflowError on a big list (22527 elements),
i'm not sure if it's only in kawa and java that the problem occur so
i'm near to code this function differently,

the error appears both in a Tomcat web app and at REPL:

 #|kawa:1|# (require 'regex)
#|kawa:2|# (include-relative  "../git/LOGIKI/lib/syntactic-sugar.scm")
#|kawa:3|# (include-relative  "../git/LOGIKI/lib/display.scm")
#|kawa:4|# (include-relative  "../git/LOGIKI/lib/case.scm") ;; for CASE with STRINGS
#|kawa:5|# (include-relative  "../git/LOGIKI/lib/map.scm") ;; for map-nil
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/map.scm:128:12: warning - no declaration seen for remove-last
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/map.scm:128:30: warning - no declaration seen for rest
#|kawa:6|# (include-relative  "../git/LOGIKI/lib/list.scm") ;; for remove-last used by map.scm
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:14:10: warning - no declaration seen for rest
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:17:32: warning - no declaration seen for rest
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:28:22: warning - no declaration seen for first
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:29:17: warning - no declaration seen for first
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:29:51: warning - no declaration seen for rest
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:35:25: warning - no declaration seen for first
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:35:56: warning - no declaration seen for rest
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:39:27: warning - no declaration seen for rest
/home/mattei/Dropbox/Jkawa/../git/LOGIKI/lib/list.scm:62:12: warning - no declaration seen for rest
#|kawa:7|# (include-relative  "../git/LOGIKI/lib/first-and-rest.scm")
#|kawa:8|# (define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
#|kawa:9|# (define wds-data-str &<{&[wds-url]}) ;; could take a few seconds to GET file
#|kawa:10|# (define wds-data-str-split (regex-split (string #\linefeed) wds-data-str))
#|kawa:11|# (length wds-data-str-split)
22527
#|kawa:12|# (define test1 (map (lambda (x) x) wds-data-str-split)
#|(---:13|# )
#|kawa:14|# (length test1)
22527
#|kawa:15|# (define test2 (map-nil (lambda (x) x) wds-data-str-split))
Exception in thread "main" java.lang.StackOverflowError
        at kawa.lib.lists.isNull(lists.scm:21)
        at kawa.lib.lists.apply1(lists.scm:20)
        at gnu.expr.ModuleBody.applyN(ModuleBody.java:243)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.mapping.ProcedureN.apply2(ProcedureN.java:39)
        at atInteractiveLevel-5.lambda7$V(stdin:10384)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)
        at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:237)
        at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:141)
        at gnu.kawa.functions.Apply.applyN(Apply.java:74)
        at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
        at atInteractiveLevel-5.lambda7$V(stdin:10396)
        at atInteractiveLevel-5.applyN(stdin:10379)

....


i think the 22527 elements list is too much for some recursion i use in my recursive functions (map-nil),
i'm a bit disappointed about scheme today, i thought my code was robust,but seems not...
it works with the original map ,i'm wondering how map is implemented ? i like coding in a recursive way , should i rewrite this with some iteration?

Regards,

Damien

 
-- 
Damien.Mattei@unice.fr, Damien.Mattei@oca.eu, UNS / OCA / CNRS

             reply	other threads:[~2017-03-15 15:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 15:08 Damien MATTEI [this message]
2017-03-15 16:23 ` Per Bothner
2017-03-16 10:54   ` Damien MATTEI
2017-03-17 11:38     ` Damien MATTEI
2017-03-17 14:07       ` Sudarshan S Chawathe
2017-03-21 14:01         ` Damien MATTEI
2017-03-21 15:47           ` Per Bothner
2017-03-25 22:56           ` Sudarshan S Chawathe
2017-03-26  9:49             ` Damien Mattei
2017-03-26  9:55               ` Damien Mattei
2017-03-26 10:56                 ` Damien Mattei
2017-03-28  8:42             ` Damien MATTEI
2017-03-28 14:21               ` Damien MATTEI
2017-03-17 10:37   ` Damien MATTEI
2017-03-17 16:00     ` Per Bothner

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=201703151608.33735.Damien.Mattei@unice.fr \
    --to=damien.mattei@unice.fr \
    --cc=kawa@sourceware.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).