IRC channel logs


back to list of logs

<havk>is there a C api for retrieving the value of a global variable previously set with scm_c_define() or scm_define() ?
<havk>I think I found it
<havk>TOPLEVEL_REF (SCM_BOOL_F, scm_from_utf8_symbol(...)) should do it
<havk>it does not work :(
<havk>but scm_variable_ref (scm_c_lookup("variable-name*")) does
***Fuuzetsu is now known as Guest26443
<ozzloy>(equal? (lambda (x) (1+ x)) (lambda (x) (1+ x))) ; => #f
<ozzloy>how do i check functions for equality in guile?
<lloda``>you can't, the best you can do is check for 'same object' which is eq?
***lloda`` is now known as lloda
<amz3>héllo guilers
<wingo_>civodul: looks to me like our bytevector output ports don't follow r6rs, in the end
<wingo_>the procedure that you call to get the bytes is supposed to take the bytes out of the internal buffer and re-set the port position
<wingo_>so i think calling the procedure again directly would return #vu8()
<wingo_>i guess people only ever call that procedure once so it's no big deal, i guess
<wingo_>or, i lie! i misread that code
<wingo_>never mind me :)
<civodul>wingo_: "bytevector output port supports `port-position'" tests that
<wingo_>ACTION hates the "char *reason" arguments to allocation procedures
<dsmith-work>Morning Greetings, Guilers
<mark_weaver>ozzloy: testing equality of procedures is formally undecidable
<random_nick>will guile ever implement common lisp?
<paroneayea>random_nick: it would be a big undertaking. Someone probably could implement it on the top of the compiler tower.
<civodul>random_nick: seems very unlikely, tho
<paroneayea>I don't know of anyone particularly motivated in #guile at the moment, but hey, maybe someone will be (maybe you would be?)
<random_nick>and will guile ever replace GNU Kawa?
<wingo>no scheme will ever replace any other scheme :)
<random_nick>that would have to be implemented under the compiler tower
<davexunit>people running Kawa are likely running it *because* it runs on the JVM, so Guile couldn't replace it.
<paroneayea>hi cluck
<cluck>hey paroneayea
<mark_weaver>I have occasionally pondered implementing just enough of common lisp on guile to run Maxima, but that's an extreme subset of common lisp.
<ozzloy>mark_weaver, i don't mean whether two procedures will always produce the same output, but whether they have the same form
<ozzloy>but ok, i guess the answer is that there isn't such a check
<davexunit>procedures can't be compared like that
<davexunit>every procedure is different
<ozzloy>i can compare them like that
<ozzloy>i can inspect them and see that they have the same form
<ozzloy>therefore procedures can be inspected like that
<ozzloy>i bet i could even write systematic rules for doing so that a computer could follow
<mark_weaver>ozzloy: having the same form isn't useful either, because the free variables referenced from the lambda expression is also part of the procedure
<mark_weaver>so there's 'eq?', but anything else would not be particularly meaningful
<rain1>ozzloy, you mean the source code of them?
<ozzloy>surely the value of the free variable is available
<rain1>or, what is it exactly you want to do?
<mark_weaver>but it's not even just the values, but the identity of them as well, if they are ever mutated
<davexunit>ozzloy: mark_weaver is correct here.
<davexunit>I think SICP might explain this in a footnote...
<mark_weaver>eq? seems to be the closest to what you seem to be looking for
<ozzloy>(something? (lambda () 1) (lambda () 1)) ; -> #t
<davexunit>if only I could remember.
<mark_weaver>the problem is, a #f response would not be meaningful
<ozzloy>rain1, ^ that's an example of what i'm trying to do
<mark_weaver>at best we could provide something that tries harder to return #t, but #f would always essentially mean "unknown"
<rain1>ozzloy, what would it do for say, (lambda () 1) and (lambda () (+ 0 1)) ?
<ozzloy>rain1, that would be #f
<rain1>alright, well to acheive this you can do this:
<rain1>(equal? '(lambda () 1) '(lambda () 1))
<mark_weaver>ozzloy: why do you want this?
<davexunit>(lambda (x) (* x 2)) (lambda (x) (+ x x))
<davexunit>are these equal?
<davexunit>equality is hard to define.
<ozzloy>i agree
<davexunit>why are these procedures not equal? what do you define equal as?
<mark_weaver>(define (make-counter) (let ((counter 0)) (lambda () (set! counter (+ counter 1)) counter)))
<mark_weaver>(define counter-1 (make-counter))
<mark_weaver>(define counter-2 (make-counter))
<mark_weaver>are counter-1 and counter-2 equal?
<mark_weaver>ozzloy: ^^
<mark_weaver>I have to go afk, but I'll look at the log later
<amz31>it sound neat to be able to compare lambdas, I don't know what it would be useful for tho.
***amz31 is now known as amz`
<ozzloy>mark_weaver, that would be equal when counter in both lambdas is equal
<ozzloy>immutability would make this a lot more useful. is there an immutability switch in guile? (use-modules (immutability)) or something?
<amz`>what's the plan? you want to compute lambdas?
<ozzloy>i don't have a use-case for this in mind. this just got me thinking about it
<davexunit>ozzloy: you cannot force immutability
<ozzloy>";; Another EXECISE, what's the proper 'equal-pred' for functions?
<ozzloy>amz`, ^
<davexunit>there is none
<amz`>there is no such thing as functions in guile, as such there is no such predicate :troll:
<rain1>nice exercise
<rain1>ozzloy, do you know Turings halting problem?
<ozzloy>i do, and i don't think this is that
<rain1>he proved that a computer can't tell if an algorithm halts or not
<ozzloy>i'm trying to think of uses. i can imagine this comparison could be useful for optimization somehow, but i'm not exactly sure how.
<rain1>and it's also true that a computer can't test if two programs are equal, for similar reasons
<ozzloy>rain1, yes, i am familiar with the halting problem. and i don't think this is that
<rain1>ozzloy, what you could try to do (if you want) is implement (define (halts? program) ...) using equal-pred
<rain1>that would be a proof (by reduction to halting) that equal-pred is not decidable
<ozzloy>oh, i said earlier that i am not trying for an equal-pred? that says whether two procedures always produce the same output
<ozzloy>just whether they have the same form
<ozzloy>so (lambda () 1) is not equal-pred? (lambda () (+ 1 1))
<davexunit>ozzloy: I think you want to be doing symbolic computation, then.
<davexunit>(equal? '(lambda () 1) '(lambda () 1)) => #t
<ozzloy>you could use lambdas as keys in a hash, and have them change in systematic ways
<ozzloy>yeah, almost exactly that, except with the ability to look up the value of the free variables at the time of comparison
<davexunit>that's not symbolic computation anymore
<ozzloy>so now you have a key for a hash that you can change in a systematic way
<ozzloy>like the counter example you gave earlier
<davexunit>you can't do what you're suggesting
<ozzloy>oh, no mark_weaver gave earlier
<ozzloy>is it not possible to look up the form of counter-1?
<ozzloy>ah, ic
<davexunit>if you are interested in the form of things, you want to be doing symbolic computation
<davexunit>in which you look at the symbols themselves, and not what they mean.
<cluck>mark_weaver, i wouldn't be surprised if elisp's cl implements enough lisp to run maxima atop guilemacs (and i fear looking, lest it become sentient and look back at me)
<ozzloy>what's the problem with bringing in the value of the symbols, other than not being able to look up the form of symbols that are lambdas?
<davexunit>I don't understand the question.
<cojy>ozzloy: <ozzloy> oh, i said earlier that i am not trying for an equal-pred? that says whether two procedures always produce the same output
<ozzloy>i'm trying to think of a way to compare forms, and if there's a free variable, compare the variable values. it sounds like the part about looking up the values is not possible, and i'm not sure why
<cojy>well you can get alpha equivalence
<cojy>which is like equal? that woudl account for differences in variable names and whatnot
<cojy>and there is no value to look up
<cojy>having a value bound in the first place means you are executing the code
<ozzloy>why is that bad?
<ozzloy>or ... is that a show stopper?
<cojy>yes that's the show stopper turing problem
<ozzloy>looking up the value of a free variable?
<ozzloy>thanks for taking the time to explain, everyone
<mark_weaver>ozzloy: if you think that counter-1 and counter-2 are equal whenever their (separate) counters happen to be equal (e.g. immediately after they are created), then that's not a notion of equality that I think is useful or interesting to me.
<mark_weaver><rain1> ozzloy, what you could try to do (if you want) is implement (define (halts? program) ...) using equal-pred
<mark_weaver><rain1> that would be a proof (by reduction to halting) that equal-pred is not decidable
<mark_weaver>rain1: that's faulty reasoning
<mark_weaver>I could implement 'zero?' in terms of (halts? program) as well, but that's not a valid argument that 'zero?' is not decidable
<rain1>oh yeah I should have said reduction to instead of redution from
<mark_weaver>a proper argument would be to show how 'halts?' could be implemented in terms of 'equal-pred'
<mark_weaver>if you can implement a general 'halts?' predicate in terms of 'equal-pred', then that would prove that 'equal-pred' is undecidable.
<mark_weaver>the reduction has to happen that way, not the other way
<rain1>yeah good point
<mark_weaver>in order to be a valid argument
<rain1>I agree with what you're saying
<rain1>and these are hypothetical programs, you can't actually run/test
<random_nick>in guile, are continuations cheaper for scheme programs with no C modules loaded?
<mark_weaver>it doesn't matter
***daviid is now known as Guest96831
<madmax96>Hey everyone. I've been using Guile's FFI, and I can't understand why the following code evaluates to false. Does anyone have any idea?
<davexunit>madmax96: because 0 and 10 are different objects
<davexunit>madmax96: what lead you to think they would be equal?
<rain1>scm->pointer allocates a new pointer object each time
<davexunit>ah yes, the more correct answer.
<davexunit>I'm too used to things like bytevector->pointer that return equivalent pointers each time because you can mutate the bytevector through C code
<madmax96>I thought that `scm->pointer` would provide the address in the context table of the variable, analogous to having a bit of c like: ... int a = 10; int *ptr_a = &a; *ptr_a = 0;
<davexunit>madmax96: okay that's roughly what I expected the confusion to be.
<davexunit>Scheme variables aren't like that.
<madmax96>So I guess my end goal is to be able to get the memory location that is bound to a symbol
<davexunit>not going to happen.
<davexunit>Scheme isn't C
<madmax96>davexunit: would you mind explaining how scheme (or guile) is handling variables or point me to a bit of literature?
<davexunit>if you want to allocate a chunk of memory that a C function couldn't write to, then create a bytevector and use bytevector->pointer.
<madmax96>I figured that was the solution, but then my problem is then being able to store any arbitrary object in that bytevector -- symbols, strings, etc.
<davexunit>madmax96: a C function wouldn't know how to interpret a Scheme symbol
<davexunit>the FFI knows how to handle numeric types directly
<davexunit>and you can convert strings and bytevectors with special procedures
<madmax96>I don't want to interpret it, I just want to protect a bit of memory using an architecture-specific opcode
<rain1>maybe you could write that part in C
<davexunit>sorry, I don't understand the problem.
<rain1>and make an interface around it?
<rain1>I don't know just an idea
<davexunit>rain1: it's best to not recommend people write C
<davexunit>until we better understand what they're actually trying to do.
<davexunit>writing C is a last resort.
<mark_weaver>madmax96: "protect" in what sense? what is the value of trying to "protect" a scheme symbol?
<mark_weaver>what exactly does this architecture-specific opcode do?
<mark_weaver>a scheme symbol is more than just a single block of memory, but in any case these details are internal to guile's implementation, and to the extent that you write code that depends on these details, it reduces flexibility for us.
<mark_weaver>e.g., I'd like to retain the option to represent scheme symbols as integer indexes into some table that we maintain, or whatever
<mark_weaver>they are a black box from your perspective :)
<madmax96>mark_weaver: an atomic compare and swap
<madmax96>I want to be able to use the builtin processor's mechanisms to protect a memory location so that I can ensure __nothing__ modifies a variable while I'm comparing and swapping it
<madmax96>From Guile's documentation, it doesn't seem like it currently has support to do this. Using a Mutex violates the spirit of the goal, so I was trying to use the FFI to access the memory location and do this.