IRC channel logs

2015-09-16.log

back to list of logs

<b4284>hi there
<b4284>i'm wondering how to work with fixed-sized integers on guile
<b4284>especially with signed integers
<mark_weaver>b4284: well, there are several ways
<b4284>i read the manual and it says the bitwise functions treats negative integers as if there are infinite ones on the left
<mark_weaver>are you accessing C data structures?
<mark_weaver>can you explain why you want fixed-sized integers?
<b4284>no, i'm not working with ffi
<mark_weaver>if it's storage efficiency that you need, there are srfi-4 homogeneous numeric vectors, which we support well
<b4284>i wanted to revert the bits of an int32
<mark_weaver>at the scheme level, we actually don't currently support doing fixed-width math directly
<mark_weaver>not currently
<mark_weaver>what does "revert" mean in this context?
<b4284>0s to 1 and 1s to 0
<mark_weaver>ah
<mark_weaver>so, srfi-60 (integers as bits) allows you to do bitwise operations on scheme's unlimited-size integers
<b4284>is invert the right word
<mark_weaver>treating them as infinitely large two-complement
<mark_weaver>b4284: yes, invert is right
<b4284>ok
<mark_weaver>srfi-60 has 'bitwise-not'
<mark_weaver>(use-modules (srfi srfi-60))
<mark_weaver>and then you have it
<nalaginrut>morning guilers~
<mark_weaver>and actually, guile already has equivalent functionality in the default environment (no need to import anything), but those aren't portable
<mark_weaver>in this case, it would be 'lognot'
<b4284>(bitwise-not #xffffffff) gives -4294967296, i was expecting an 0
<b4284>i must have missed something
<mark_weaver>(bitwise-not -1)
<mark_weaver>these are not fixed-width integers, they are unlimited length
<mark_weaver>but still interpreted as twos-complement for purposes of these operations
<mark_weaver>so, one way to think of it is that since the positive number #xffffffff cannot fit in a 32-bit signed integer, it is upgraded to a large size automatically.
<mark_weaver>with these unlimited-size integers, a positive number will never become negative due to overflow, which is the behavior in C that you are depending on here to expect #xffffffff to be equal to -1
<mark_weaver>b4284: if you need to import numbers like #xffffffff, you need to sign-extend the high-bit, just as you would when converting from int32_t to int64_t
<b4284>ok, let me chew on it for a while
<mark_weaver>where are the numbers like #xffffffff coming from?
<mark_weaver>in guile, you can do that sign extension like this: (centered-remainder #xffffffff (expt 2 32))
<b4284>mark_weaver: i'm just typing and printing it out to figure out its behavior
<b4284>mark_weaver: wow, never thought there's a function like centered-remainder
<mark_weaver>there are several different variants of DIV and MOD in guile
<b4284>mark_weaver: thank you
<mark_weaver>you're welcome!
<mark_weaver>'centered-remainder' should also simulate the effect of overflow for signed addition and subtraction at least, and probably also multiplication, although I'm not quite sure about that.
<mark_weaver>however, that is the effect of signed overflow in the hardware. in practice, C now has different behavior on signed overflow.
<mark_weaver>modern C compilers are allowed to assume that signed overflow will never happen, and aggressively optimize the code based on that assumption
<mark_weaver>so, for example, if you multiply two signed positive integers A*B=C and check for overflow by checking if C/B=A, modern C compilers will literally remove that check as dead code.
<mark_weaver>unsigned arithmetic is different. it's allowed, and has guaranteed portable semantics.
<b4284>learning c as well :)
<b4284>i mean, one can also learn about C in this channel :)
<mark_weaver>heh :)
<mark_weaver>s/it's allowed/overflow is allowed/
<mark_weaver>b4284: if you're comfortable sharing, I'm curious to hear why you want these fixed-width operations. it might help be better point you in the right direction.
<mark_weaver>s/be/me/
<mark_weaver>(and if it's just for learning or playing, that's fine too :)
<b4284>yeah, it's pretty much just playing with it
<b4284>because i work with C, so i have to deal with signedness and endianness a lot
<sprang>hi guilers
<sprang>I was wondering if there is a standard scheme function that does something like this?
<sprang>(define (use-if test value) (if (test value) value #f))
<mark_weaver>sprang: not that I know of
<mark_weaver>I might write that as (and (test value) value)
<sprang>mark_weaver: ok, thanks. suggested rewrite is elegant
<nalaginrut>ACTION done his post
<uu_>hi, can I use guile in C++ projects? will it link correctly with c++ runtime?
<nalaginrut>uu_: I think it's fine
***lloda` is now known as lloda
<amz3>héllo :)
<uu_>guile currently does not seem to have rich libraries
<uu_>I am a little worried about adding it to my project
<uu_>compared with lua/ python
<uu_>could you give me some advice?
<uu_>nalaginrut: :)
<amz3>what is your library uu_
<nalaginrut>uu_: IMO, at present, for client side, python maybe better, unless you are not in a pressure to done the work, you may try guile
<nalaginrut>I confess I incline to python in client side when I do some not-for-fun work
<nalaginrut>uu_: I do so because I want to save my time for better hacking
<nalaginrut>uu_: but if you want to try some cool ideas, I would recommend use Guile as possible
<nalaginrut>use python do the boring work, when I pick up Guile, I want to be cool
<nalaginrut>uu_: but in server side, I use Guile only ;-)
<uu_>nalaginrut: thanks for your advice. guile seems easier to integrate compared with python
<nalaginrut>uu_: yes, it's good for embedding into c/c++ programe
<nalaginrut>and the FFI is cool to use too
<nalaginrut>of course, a better framework based on FFI is better, but it's enough for the work
<taylanub>this isn't integrated well with the FFI yet but I plan to work on that soon: https://github.com/taylanub/scheme-bytestructures
<uu_>FFI -- its name! I used it but I didnot know its name
<uu_>for python, I hope there could be something like ctypes for c++
<ArneBab>uu_: what functionality do you need?
<uu_>I once exported some api after warping my c++ func. to c
<ArneBab>(compared to Python or Java everything has few libraries at the moment…)
<ArneBab>(except if you count C++ ☺)
<uu_>ArneBab: currently I have written up a somewhat complex "system", and it accepts some input and some configurations. Now I want to play with different inputs and configurations.
<ArneBab>do you need access to stuff like netcdf data files or specific online-services (for which Python libraries exist)?
<ArneBab>uu_: do you want to ship the system to users?
<uu_>currently the system works by loading a input file and a configuration file, which makes it hard to play
<uu_>sometime ago, I found cling: https://root.cern.ch/cling
<uu_>it is amazing. and it seems it could save me a script extension system
<uu_>ArneBab: it is a research project
<uu_>the final user is me and my collegues
<ArneBab>that’s already a good situation for using Guile :)
<ArneBab>so you’d build a shell or a commandline application?
<ArneBab>(interactive shell)
<uu_>haha. yeah, I will try it
<ArneBab>if the input files are large, an interactive shell might be better: only load each file once and then try different configurations
<ArneBab>it sounds like you won’t really need lots of libraries
<ArneBab>but the ability to improve the scripting language with macros could save you lots of hassle
<ArneBab>I used Python for my plotting framework and in the end designed extensive commandline control with lots of caching to make it usable.
<ArneBab>(at work)
<amz3>uu_: there is framework for C++ it's built by pypy, I don't recall the name
<amz3>cppyext maybe
<amz3>I agree with nalaginrut, I wish I did more guile :/
<nalaginrut> http://nalaginrut.com/archives/2015/09/16/actor-model%3A-a-revealed-black-box-in-scheme
<amz3>\\o/
<nalaginrut>ACTION go home~
<wleslie>the 'plugins' on the website mock-up reminds me of vihart's "the bowl and the lazer bat"
<amz3>I have a the feeling that it's too child-ish
<amz3>I like it but, maybe it's doesn't look serious enough
<healer>Came across http://interim.mntmn.com/ and http://dump.mntmn.com/interim-paper/ today via https://news.ycombinator.com/
<healer>Just wondering if guile will not be a perfect candidate language for this sort of thing
<remi`bd>:o
<civodul>healer: looks interesting
<civodul>GuixSD still uses Linux-libre as its device driver; Interim looks like the next step ;-)
<healer>civodul: Yeah, the way guile is structured and tightly integrated into C, methinks implementing this will be a no-brainer to guile-hackers out there
<uu_>amz3: you mean cppyy, it looks like it depends on cling (ROOT)
<healer>for educational purposes at least
<healer>Though guile is large now
<ArneBab>I like the website mock up, too ☺
<davexunit>I see that the guildhall github account forked my old guile-zlib repo
<davexunit> https://github.com/davexunit/guile-zlib
<davexunit>guess I should release it ;)
<taylanub>does anyone know what struct packing and alignment configurations are useful to implement in an FFI system? so far I support decreasing padding (like '#pragma pack(n)'), but not increasing it (like '__attribute__ ((aligned (n)))'). is the latter worth supporting? do C libraries with a stable ABI ever use it?
<civodul>davexunit: didn't know you had worked on that
<civodul>it's going to be useful to 'guix publish'!
<civodul>s/to/for
<davexunit>civodul: I had forgotten!
<davexunit>3 years old
<civodul>haha :-)
<davexunit>will it be useful there? I thought we need bzip2 compression?
<civodul>i'd bet it can support libbz2 for maybe 10 additional lines of code
<davexunit>ooh
<davexunit>well I should look into sometime
<davexunit>and release this thing
<davexunit>and move it off of github
<civodul>yep!
<zacts>hello guile
<ahmedtd_>taylanub: If it exists, a C library has used it
<ahmedtd_>I mean, even guile is a C library, "technically"
<ahmedtd_>And look at all the weird crap it does
<ahmedtd_>A better question is whether you should worry about it
<ahmedtd_>the answer is "probably not"
<ahmedtd_>But increased alignment is sometimes used when you want to force structs to lie along cache or page lines
***dje is now known as xdje
<paroneayea>ACTION learns the (cond ((8 => (lambda (x) (+ x 2))))) syntax
<paroneayea>neat
<paroneayea>I didn't know about that
<rekado>do you know if anyone is currently working on speeding up Guile Emacs? Is this a general Guile compilation problem or is it specific to Guile's elisp support?
<paroneayea>rekado: the last time I talked to bipt they said there were known ways they could optimize things
<paroneayea>and were optimistic abou tit
<paroneayea>I don't know what their schedule is like... at the time they were optimistic they would have time to work on it, but we all know how life things can go
<paroneayea>it would be great to see some updates though
<rekado>thanks
<paroneayea>I'm very interested in seeing guile-emacs succeed
<paroneayea>maybe over time I'll become knowledgeable enough to help in some smaller way
<paroneayea>s
<paroneayea>than just packaging for guix ;p
<rekado>I'd *love* to use Guile Emacs. The more Guile the better.
<paroneayea>I agree!
<daviid>what is the traditional/recommended autool location where to install examples ?