Re: prompts: any example ?
l...@gnu.org (Ludovic Courtès) writes: > Hi Ian, > > Excellent illustration, thank you! > > Ian Price skribis: > >> https://gist.github.com/1548531 - monadic reflection > > Could you expound on this one? I can feel the greatness, but I don’t > fully grasp it. :-) Yes, and it doesn't help that it is missing a bunch of helpers :) I no longer have the original file, so I can't even remember if I stomped out the bugs in it(probably not). The trick comes from, I think, Filinski's "Representing Monads", although it has been quite a while since I've read it. Instead of monads being represented by the usual 'bind' and 'unit' functions, or the (categorical?) definition of 'unit', 'fmap', 'join', they are instead represented by two operators 'reflect' and 'reify'. reify : (() -> a) -> m a reflect : m a -> a reify takes a function that returns a value, and returns a monadic value i.e. it lifts a pure expression to an effectful one. reflect takes a monadic value and returns the value. i.e. it lowers the effectful value into the pure layer. This representation has two nice properties. Firstly, we get direct style back :-). This one is important to me, and reflects the fundamental reason why we need continuations: To rescue us from the horror of forced styles :). The second one, which I don't think he mentioned in that paper (maybe in "representing layered monads"?) is that tagged delimited continuations actually allow us to use multiple monads quite naturally, without the need to invent things like monad transformers. In that example, I quite naturally mix the reader and state monads. It isn't quite perfect: the 'do-rename' function is not pretty, some functions like 'with-extended-environment' need to take a thunk, and without inference we need a different named reflect/reify for each monad, but it seems relatively useful and I was quite obsessed with it for a time. -- Ian Price "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled"
Re: Problem with modules in Guile 2.0
Gubinelli Massimiliano writes: > I stumbled on a strange behaviour of Guile 2.0, I have the following three > files: main.scm, test-module.scm and sub/mymodule.scm which respectively > contain > > main.scm > > (load "test-modules.scm") > > (inherit-modules (sub mymodule)) > > (display (pippo 10 20)) (display "\n") The problem is that 'load' is done only at run time, not compile time, so the compiler does not have access to the macro 'inherit-modules'. Since Guile 1.x did not have a compiler, this was not an issue. One easy solution would be to use the 'include' macro instead. 'include' acts like '#include' in C: it splices the entire contents of the included file in place of the 'include' form, at compilation time. 'include' did not exist in Guile 1.x, but you could do something like this to make 'include' an alias for 'load' in Guile 1.x: (cond-expand (guile-2 #f) (guile (define include load))) Best, Mark
Re: Problem with modules in Guile 2.0
Hi! Mark gave great answers; I just wanted to give one more option: On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano writes: > (load "test-modules.scm") Add a definition first: (cond-expand (guile-2 (define-syntax-rule (begin-for-syntax form ...) (eval-when (load compile eval) (begin form ... (else (define begin-for-syntax begin))) Then: (begin-for-syntax (load "test-modules.scm")) Regards, Andy -- http://wingolog.org/
Re: Problem with modules in Guile 2.0
Thanks for the prompt reply to both of you. However the proposed solution do not work in my case. After implementing the begin-for-syntax alternative I now get scheme@(guile-user)> (load "main.scm") ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm ;;; note: source file /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm ;;; newer than compiled /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:15:34: warning: possibly unbound variable `compile-interface-spec' ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:32:11: warning: possibly unbound variable `:use' ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:33:11: warning: possibly unbound variable `:inherit' ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:34:11: warning: possibly unbound variable `:export' ;;; compiled /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go ;;; WARNING: compilation of /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm failed: ;;; ERROR: No variable named %module-public-interface in # ERROR: In procedure scm-error: ERROR: No variable named %module-public-interface in # Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> if I understand correctly this backtrace it seems that the module is not completely loaded at compile time and there is not public interface available. How can I force the evaluation of the loaded modules in order to get a list of exported symbols? Best massimiliano On Mar 7, 2012, at 9:32 PM, Andy Wingo wrote: > Hi! > > Mark gave great answers; I just wanted to give one more option: > > On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano > writes: > >> (load "test-modules.scm") > > Add a definition first: > > (cond-expand > (guile-2 >(define-syntax-rule (begin-for-syntax form ...) > (eval-when (load compile eval) (begin form ... > (else >(define begin-for-syntax begin))) > > Then: > > (begin-for-syntax > (load "test-modules.scm")) > > Regards, > > Andy > -- > http://wingolog.org/ On Mar 7, 2012, at 9:32 PM, Andy Wingo wrote: > Hi! > > Mark gave great answers; I just wanted to give one more option: > > On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano > writes: > >> (load "test-modules.scm") > > Add a definition first: > > (cond-expand > (guile-2 >(define-syntax-rule (begin-for-syntax form ...) > (eval-when (load compile eval) (begin form ... > (else >(define begin-for-syntax begin))) > > Then: > > (begin-for-syntax > (load "test-modules.scm")) > > Regards, > > Andy > -- > http://wingolog.org/
Re: Problem with modules in Guile 2.0
Gubinelli Massimiliano writes: > Thanks for the prompt reply to both of you. However the proposed > solution do not work in my case. I think it _did_ solve your original problem, but now you have moved on to other unrelated problems. > After implementing the > begin-for-syntax alternative I now get > > scheme@(guile-user)> (load "main.scm") > ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm > ;;; note: source file > /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm > ;;; newer than compiled > /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go > ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm > ;;; > /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:15:34: > warning: possibly unbound variable `compile-interface-spec' Note that 'compile-interface-spec' was an undocumented internal procedure of Guile 1.x, and no longer exists in Guile 2. > ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:32:11: > warning: possibly unbound variable `:use' > ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:33:11: > warning: possibly unbound variable `:inherit' > ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:34:11: > warning: possibly unbound variable `:export' In order to use the shorter keyword syntax ':use' (instead of '#:use'), you must set the prefix keywords reader option. Put the following at the beginning of your 'begin-for-syntax' form: (read-set! keywords 'prefix) > ;;; compiled > /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go > ;;; WARNING: compilation of > /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm failed: > ;;; ERROR: No variable named %module-public-interface in # mymodule) 10507ed80> > ERROR: In procedure scm-error: > ERROR: No variable named %module-public-interface in # mymodule) 10507ed80> > > Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. > scheme@(guile-user) [1]> > > if I understand correctly this backtrace it seems that the module is > not completely loaded at compile time and there is not public > interface available. How can I force the evaluation of the loaded > modules in order to get a list of exported symbols? I cannot reproduce this. When I try using your example code, Guile 2.0.5 tries to compile (sub mymodule). Are you sure that you remembered to set GUILE_LOAD_PATH during this test run? This is what I see: GNU Guile 2.0.5 Copyright (C) 1995-2012 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (load "main.scm") ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument to disable. ;;; compiling /home/mhw/guile-modules/main.scm ;;; compiling /home/mhw/guile-modules/./test-modules.scm ;;; test-modules.scm:15:34: warning: possibly unbound variable `compile-interface-spec' ;;; compiled /home/mhw/.cache/guile/ccache/2.0-LE-4-2.0/home/mhw/guile-modules/test-modules.scm.go ;;; compiling /home/mhw/guile-modules/sub/mymodule.scm ;;; sub/mymodule.scm:1:0: warning: possibly unbound variable `texmacs-module' ;;; sub/mymodule.scm:1:16: warning: possibly unbound variable `sub' ;;; sub/mymodule.scm:1:16: warning: possibly unbound variable `mymodule' ;;; compiled /home/mhw/.cache/guile/ccache/2.0-LE-4-2.0/home/mhw/guile-modules/sub/mymodule.scm.go ;;; WARNING: compilation of /home/mhw/guile-modules/main.scm failed: ;;; ERROR: In procedure module-lookup: Unbound variable: texmacs-module sub/mymodule.scm:1:0: In procedure #: sub/mymodule.scm:1:0: In procedure module-lookup: Unbound variable: texmacs-module Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(#{ g435}#) [1]> and the problem here is that the compilation of sub/mymodule.scm fails because the 'texmacs-module' macro was used before it was imported into that module. Initially, a module imports only the (guile) module. If you want to use a non-standard module declaration like 'texmacs-module' at the top of a module, you'll need to add that binding to the (guile) module. Best, Mark