IRC channel logs

2017-03-21.log

back to list of logs

<ArneBab>would it be viable to implement an (ice-9 racket) with an interoperability layer to be able to run most racket code?
***alphor_ is now known as alphor
<nalaginrut>davexunit: what's the status of chickadee now ;-) ?
<davexunit>nalaginrut: same it was as of the last release
<spk121>good evening!
<wingo>ArneBab_: no.
<wingo>regarding statprof
<dsmith-work>Morning Greetings, Guilers
<daviid>hello *
***rubdos_ is now known as rubdos
<amz3>o/
***dje is now known as xdje
<OrangeShark>o/
<joshuaBPMan_>Hello, I'm trying to solve a reddit daily programming in guile, just for fun. As a warm up exercise to that I'm trying to create a function that prints "1 2 3" via recursion and uses a closure. I'm trying to copy the guile info manual, but it doesn't seem to work for me. Here's my paste bin: http://pastebin.com/vPLbYYKD
<davexunit>you've made a procedure that returns a procedure
<davexunit>(define (1-3) ...) defines a procedure
<davexunit>and the (lambda () ...) is the return value
<davexunit>which is certainly not what you were trying to do
<joshuaBPMan_>hmmmm. davexunit: Are you in #wordpress a lot? I feel like you've helped me out there before....
<janneke>also, the optional second parameter to display should be a port
<davexunit>joshuaBPMan_: nope
<joshuaBPMan_>hmmm. I'll have to read the info manual again. I feel like that was the example that they gave...
<joshuaBPMan_>I was looking at 3.4.6 Example 1: A Serial Number Generator
<joshuaBPMan_>There's a short example. I'll try looking at the code closer.
<davexunit>there's probably about a dozen things weird going on in your code
<davexunit>the only thing that makes it not work is the way you define the function
<davexunit>everything else is just bad style
<davexunit>if you took the parens away from the first instance of (1-3), it should work
<joshuaBPMan_>hmm. I am a noob, so that's probably why it's soo odd looking. I really ought to read more about how to structure scheme code.
<joshuaBPMan_>oh duh.
<davexunit>mutating a variable isn't a great idea
<davexunit>calling (1-3) will only work once
<davexunit>calling it multiple times will do absolutely nothing
<joshuaBPMan_>actually no. I can't remove the parenthesis from the first instance of (1-3) then it would be (define 1-3 (let) ....)
<davexunit>joshuaBPMan_: yes, you can.
<joshuaBPMan_>If you're trying to say do a (define 1-3 (lambda)) ...
<joshuaBPMan_>ok. I'll try it...
<davexunit>literally leave everything the same
<davexunit>except remove those parens
<janneke>better remove the lambda ()
<davexunit>janneke: one thing at a time
<janneke>davexunit: sure, sorry ;-)
<davexunit>joshuaBPMan_: also as janneke points out your call to 'display' is wrong
<joshuaBPMan_>So I ran (define 1-3 (let ...)) (1-3) doesn't work.
<davexunit>the call to display is wrong
<joshuaBPMan_>hmmm
<davexunit>you cannot pass a string as the second argument
<davexunit>the second argument is the port to write to
<davexunit>to display 'x' and then a space, you need 2 calls
<davexunit>(display x) and then (display " ")
<joshuaBPMan_>ok
<joshuaBPMan_>thanks for the help
<davexunit>joshuaBPMan_: you're welcome. in the future, please avoid using pastebin.com. they do many bad things, including blocking tor users.
<davexunit>and some people that could help you in this channel browse with tor
<davexunit>joshuaBPMan_: here's how I would write the 1-3 procedure: http://paste.lisp.org/display/342017
<davexunit>you can call 1-3 multiple times and it will output "1 2 3 " every time
<davexunit>unlike the one you wrote
<joshuaBPMan_>davexunit: Is that a "name let"
<davexunit>named let, yes.
<joshuaBPMan_>the let is defining a procedure and calls it again?
<joshuaBPMan_>and again?
<joshuaBPMan_>thanks for the help
<davexunit>yeah basically
<joshuaBPMan_>ok cool.
<davexunit>joshuaBPMan_: see http://paste.lisp.org/display/342017#1 for an example that doesn't use let at all
<joshuaBPMan_>Your code must also have a closure in it as well. Is "named let" syntactic sugar that removed the need to write a lambda right after the let?
<joshuaBPMan_>aka (let loop ((x 1)) ....) == (let loop (lambda (x 1) ...)) ?
<davexunit>joshuaBPMan_: no
<joshuaBPMan_>oh bummer. It was all coming together...
<davexunit>it's more like the last thing I sent you
<joshuaBPMan_>the define within the define
<davexunit>the lambda needs to be given a name so that you can call it again and again
<joshuaBPMan_>inner...ok.
<OrangeShark>joshuaBPMan_: you need to use a closure?
<joshuaBPMan_>OrangeShark: I don't need to I suppose. davexunit showed me how I can output numbers without it...It would be nice to know how to use closures, because they sound pretty awesome.
<OrangeShark>joshuaBPMan_: Oh, I thought that was one of the requirements
<davexunit>joshuaBPMan_: that 'inner' procedure *is* a closure
<davexunit>the procedure '1-3' "closes over" the procedure 'inner'
<davexunit>'inner' is only defined within '1-3'
<OrangeShark>davexunit: I think joshuaBPMan_ wanted it to use a closure to keep track of the number like in the example they referenced in the guile manual
<joshuaBPMan_>OrangeShark: I understand a closure is something like a static variable. All the variables in the closure keep their same values.
<joshuaBPMan_>If I use just plain recursion w/o a closure I thought it would be harder.
<davexunit>OrangeShark: okay, but a closure just doesn't make sense in this case.
<OrangeShark>davexunit: I agree.
<OrangeShark>joshuaBPMan_: a closure is more like data that can be used by a function that was passed as an argument or returned by a function
<joshuaBPMan_>So the named let is syntatic sugar for davexunit second peice of code that said (define (1-3) (define (inner x)))
<OrangeShark>when that function was returned or passed an argument
<joshuaBPMan_>hmmm. I'll hopefully wrap my head around it eventually.
<OrangeShark>joshuaBPMan_: in davexunit's code, the state is passed through the recursion and not a variable outside the function
<OrangeShark>the 3.4.6 example uses a closure to allow you to create functions with their own little memory which is the number it keeps track of
<joshuaBPMan_>What I was trying to do was create a function that'll accept (number1 . number2) as input and output their lowest common factor or #f if it does not exist. My incomplete code is here: http://paste.lisp.org/display/342020 Essenitally I am trying to make factor a static variable...So it remembers it's value from the previous call.
<OrangeShark>when you call (make-serial-number-generator), it creates a closure with `current-serial-number` and returns a function that references the closure.
<joshuaBPMan_>hmmm.
<OrangeShark>then you can call that function each time to increment that number which is unique to that function
<joshuaBPMan_>ok.
<Walakea>how does guile work together with C++ code?
<joshuaBPMan_>Walakea: no idea. haha.
<joshuaBPMan_>You can try looking at the guile manual. I think it has a section about that.
<spk121>Walakea: ffi interface is not good with c++. Also, since guile uses setjmp, using c++ exceptions can cause problems.
<spk121>Walakea: or so I've heard. I've never tried it.
<amz3>tho they are projects using c++ and guile
<joshuaBPMan_>Can guile easily call rust code?
<amz3>like https://github.com/mkeeter/ao/
<wingo>good evening guilefolks
<amz3>never heard of anyone trying but AFAIK Rust was built to be compatible with C
<amz3>at the ABI level I think... not sure about that
<random-nick>joshuaBPMan_: no unless the rust code exposes a C interface
<random-nick>joshuaBPMan_: since guile only has a C Foreign Function Interface
<random-nick>joshuaBPMan_: or if rust code registers gsubrs
<joshuaBPMan_>random-nick: Ok.
<joshuaBPMan_>is (begin ...) essential to elisp's (progn ...) ?
<joshuaBPMan_>aka they are the same?
<wingo>pretty much
<joshuaBPMan_>thanks wingo: also good evening to you.
<spk121>hey all. If I can call (current-source-location) and (current-filename), it is possible to have a (current-procedure) procedure?
<wingo>spk121: humm, good question... what would it do? :)
<wingo>ACTION writes an "eval-in-sandbox" function
<spk121>wingo: imagine it for a message in an assertion macro or a logging call.
<wingo>spk121: what name do you give tho? i assume it evaluates to a name.
<wingo>like how do you give a procedure a name that is used inside the procedure
<wingo>when a procedure is a value that can many names or no name
<spk121>wingo: dunno. :-) I know you can print a stack trace, so the moving up the stack trace to the first location with an associated procedure name?
<paroneayea><ArneBab> would it be viable to implement an (ice-9 racket) with an interoperability layer to be able to run most racket code?
<paroneayea>ArneBab_: well one problem is that Racket has so many languages
<paroneayea>which one? ;)
<wingo>i really like racket's #lang thing
<paroneayea>it's pretty cool
<wingo>for example i was thinking in guix to be able to have the package.scm be a more stable API from guix -- in that case you might want to use a #lang guix-universe-package
<wingo>dunno
<wingo>spk121: it is an interesting question :) of course you can get that info at run-time. but the value is getting it at expansion time
<wingo>but expansion-time is pre-optimization, and run-time is post-optimization...
<wingo>dunno, i think you would need the expander to keep a kind of fluid value of what the current procedure name is.
<wingo>and it would be somewhat limited, like loops would be in nested procedures
<wingo>so they probably wouldn't have names
<spk121>wingo: Well, logging is only valuable at runtime. Assertions are sometimes valuable at compile time.
<spk121>wingo: anyway, I was just curious.
<wingo>yeah sorry to not have a great answer :)
<wingo>is the after-gc-hook just not getting called
<wingo>wtf
<thomassgn>What does the '%' in %variables mean? does guile care? and is there any resource I can reference to check for this? guile-beginner-9000
<thomassgn>(:
<wingo>:)
<spk121>thomassgn: in general % indicates that a thing is low level or internal
<spk121>thomassgn: but, it is just a naming convention.
<paroneayea>thomassgn: it is also used for dynamic / fluid things
<paroneayea>for example, parameters
<wingo>yeah we need to write these up. unfortunately there's no canonical reference so people do whatever they want :)
<paroneayea>but as spk121 said, it's just a convention... and a very vague one
<thomassgn>ah, thanks.
<paroneayea>wingo: I think maybe the naming convention I occasionally worry about the most is whether or not it's acceptable to put *? suffix on a boolean procedure argument
<paroneayea>wingo: seems pretty common, esp with keywords... (define* (foo #:key bar?) ...)
<paroneayea>but now we're using that both for predicates and boolean values
<paroneayea>which is... hm, I'm never sure if it's great, though I do it sometimes too
<wingo>clearly we need to embed ml into our naming conventions
<paroneayea>wingo: my brother argues that scheme's use of *! and *? are code smells, because they betray that the system can't indicate those things for you... but he's much more of a type-y neat, and I'm much more of a scruffy, so it doesn't bother me :)
<spk121>We can bring back reverse polish notation, for the win!
<amz3>no guile gsoc idea page?
<amz3>I don't have gsoc idea tho
<janneke>mes compiled by mescc now runs scheme program that implements full scheme reader
<spk121>janneke: neato
<janneke>previous target was running memory-dumped programs like '(cadr (cons 1 2))' ;-)