ChanServ changed the topic of #picolisp to: PicoLisp language | Channel Log: https://irclog.whitequark.org/picolisp/ | Check also http://www.picolisp.com for more information
orivej has quit [Ping timeout: 260 seconds]
Blukunfando has quit [Ping timeout: 260 seconds]
Blukunfando has joined #picolisp
<aw-> Regenaxer: hi, i wonder why this doesn't produce an error: (hex "1G5K") .. it's clearly not a hex value..
_whitelogger has joined #picolisp
<tankf33der> aw-: because validation is coders responsobility
<tankf33der> it returns NIL, right? this is sign something is bad
<tankf33der> :)
<Regenaxer> Yes. Just like other number converions ('format', 'date', 'time' etc.)
<Regenaxer> An error is less useful
Blukunfando has quit [Ping timeout: 256 seconds]
Blukunfando has joined #picolisp
Blue_flame has quit [Quit: killed]
Blue_flame has joined #picolisp
rob_w has joined #picolisp
_whitelogger has joined #picolisp
<tankf33der> now completely understood fixed point math in picolisp. and can solve any tasks on it even in head.
<tankf33der> last time i told this a year ago.
<tankf33der> :)
<aw-> Regenaxer: tankf33der it doesn't return NIL
<tankf33der> aw-: ok
<aw-> : (hex "1G5K")
<aw-> -> 4180
<aw-> this makes no sense
<tankf33der> sure, do validation yourself before hex call
<aw-> tankf33der: yes i know, i can do that, but i think it's wrong
<aw-> PicoLisp should not convert non-hex values to a random integer
<tankf33der> all this increase runtime complexity
<aw-> it's inherently wrong to perform the conversion
<tankf33der> do validation yourself if needed
<aw-> how does it even decide how to convert 1G ? that's not even hex
<aw-> what is the rule?
<aw-> does it roll over so G becomes 0?
<tankf33der> in real life 100% of jsons is valid, right? :)
<tankf33der> and hex the same.
<aw-> oh it continues
<aw-> (hex "G")
<aw-> -> 16
<aw-> (hex "G") should be NIL, not 16
<aw-> this is so wrong
<tankf33der> hex source is trivial, check how simple it is
<aw-> i know how to validate hex, i'm not arguing about that
<tankf33der> hex expects correct input.
<aw-> why does (format 123a) return NIL ?
<aw-> but (hex "G") doesn't ?
<aw-> it's inconsistent
<tankf33der> eventually.
<aw-> dunno
<aw-> i think this is a bug in PicoLisp
<aw-> it should not return an integer and make me think the conversion was correct
<aw-> or at least, it should return NIL or 0
<tankf33der> Regenaxer: what you think?
Blukunfando has quit [Ping timeout: 240 seconds]
Blukunfando has joined #picolisp
orivej has joined #picolisp
<Regenaxer> ret
<Regenaxer> Yeah, hex, oct, bin should return NIL
<Regenaxer> (I thought they do)
<Regenaxer> '0' is not a good idea
<Regenaxer> Will change for pil21
orivej has quit [Ping timeout: 260 seconds]
orivej has joined #picolisp
<Regenaxer> Also will remove 'fmt64', this was only for pil32
<Regenaxer> OK, fixed and released :)
<Regenaxer> aw-, can you test when you have time?
<Regenaxer> Demo in app/ runs now
<Regenaxer> I put it into a separate TGZ: https://software-lab.de/demoApp.tgz
orivej has quit [Ping timeout: 240 seconds]
<aw-> oh wow! ok im testing now
<aw-> Regenaxer: can you remove .SILENT from the makefile too?
<aw-> i think it's good to know what the build is doing
<Regenaxer> I don't like verbosities
<aw-> oh ok
<Regenaxer> This info is seldom needed, you can just comment it in such cases
<Regenaxer> The build is so simple anyway, and is usually not touched for years
<aw-> new release (hex) works perfectly
<Regenaxer> cool, thanks!
<aw-> thank you!!
<Regenaxer> :)
<aw-> ok im gonna convert all my code to use pil21 by default
<aw-> all of it is already confirmed working with pil21
<Regenaxer> Good idea
<Regenaxer> I do so too, first with local non-producwion servers
<Regenaxer> But first I have to convert PilBox to pil21
<aw-> Regenaxer: one more thing about (hex).. i typically use (pad 2 (hex Num))
<aw-> because (hex) doesn't do it by default.. i wonder if that should be "fixed" too
<Regenaxer> hmm
<Regenaxer> but 2 is not enough
<Regenaxer> could be 4 or 8 etc
<aw-> yes i mean for just a single digit
<Regenaxer> true
<Regenaxer> but tedious ;)
<Regenaxer> hex etc are not oriented at that level
<Regenaxer> ie keep track of the number of digits
<aw-> right
<Regenaxer> How would you do it?
<aw-> one sec, i wrote code which handles that
<Regenaxer> And what about 'bin' and 'oct' then?
<aw-> my code for hex does this: (lowc (pack (mapcar '((N) (pad 2 (hex N))) (chop Str))
<aw-> wait let me check again
<Regenaxer> Str has hex-digits?
<Regenaxer> then pad 2 is not right
<aw-> no that's no it
<Regenaxer> you need to collect pairs
<Regenaxer> the 'until' loop needs to be changed
<Regenaxer> do it twice
<Regenaxer> calling hex1 four times
<aw-> sorry, str was not str
<aw-> (lowc (pack (mapcar '((N) (pad 2 (hex N))) Lst)))
<aw-> list of integers between 0 and 255
<Regenaxer> ok
<Regenaxer> We need to double the two lines in hex
<Regenaxer> the second arg to hex seems to group
<Regenaxer> : (hex 123456789 4)
<Regenaxer> -> "75B CD15"
<Regenaxer> So this is the place to modify
<aw-> yeah maybe not a good idea to implement that
<Regenaxer> I agree that it would be more readable
<aw-> but it introduces problems too
<Regenaxer> pad to 2, or to the second arg
<aw-> ex: (hex "a") = 10, (hex "0a") = 10, (hex "aa") = 170 and (hex "0a0a") = 2570
<aw-> you will break a lot of code if you change the way (hex) works
<Regenaxer> Ah, I thought you mean the other direction
<Regenaxer> see example above
<aw-> oh sorry, yes I did
<aw-> i confuse myself hahaa
<Regenaxer> would give would
<Regenaxer> would give "075B CD15"
<aw-> right
<aw-> that's what i would expect to receive
<Regenaxer> So pad to 'I' or 2 by default
<Regenaxer> It depends what you need
<Regenaxer> Avoiding a zero reduces bandwidth
<Regenaxer> only if for humans to read it is useful
<Regenaxer> But you can easily post-process the output
<Regenaxer> with split and pad
<aw-> well isn't it only missing one padding 0 at the beginning?
<aw-> no that's right, it misses padding always, so you can't easily pack a series of hex values
<aw-> (pack (hex 10) (hex 10)) gives totally wrong result
<Regenaxer> How about this:
<Regenaxer> $: (pack (mapcar '((X) (pad 4 (pack X))) (split
<Regenaxer> (chop (hex 12345678 4)) " ")))
<Regenaxer> -> "00BC614E"
<Regenaxer> So you can cook it up
<aw-> yes that's exactly what I do now
<aw-> similar
<aw-> so you're suggesting pad to the second argument?
<Regenaxer> : (pack (mapcar '((X) (pad 4 (pack X))) (split (chop (hex (hex "100230045" 4))) " ")))
<Regenaxer> -> "100230045"
<Regenaxer> No, write a function like the above
<aw-> i did
<aw-> my function works fine
<Regenaxer> ah, ok
<Regenaxer> good then :)
<aw-> i'm wondering if (hex) should do it by default
<Regenaxer> I think better not
<Regenaxer> save the zero if not needed
<aw-> ok
<Regenaxer> A leading zero means "octal" if parsed by other languages
<aw-> right right
<aw-> this is fine, i'll handle it in my code
<Regenaxer> great
<Regenaxer> Anyway it is better to keep the primitives simple
<Regenaxer> Easier to pad an output than to remove undesired default stuff
<aw-> agreed
<beneroth> <Regenaxer> Easier to pad an output than to remove undesired default stuff
<beneroth> aye
<beneroth> this is a essential picolisp pillar
<Regenaxer> :)
<beneroth> which also explains why some/many functions don't validate their input
<Regenaxer> yeah, depends
<Regenaxer> Most return NIL
<beneroth> in principle I agree with aw-, everything should validate everything all the time, so any mistakes are detected as quick as possible, not chaining all over the place
<Regenaxer> right
<Regenaxer> hex did not do that
<Regenaxer> now it returns NIL
<beneroth> but picolisp is an optimized interpreter, and runtime checks cost time, and in many use cases the code can practically only have such errors during development
<beneroth> so I also agree with you, Regenaxer :)
<Regenaxer> :)
<beneroth> leaving the runtime checks away, allows to make a wrapper around it anytime
<beneroth> or patching it (which is an invisible wrapper) using (redef)
<beneroth> but the other way is not so easily available
<Regenaxer> right
<beneroth> the issue boils down to managing the expectations of the programmers :)
<Regenaxer> on the other hand, if things are checked anyway (to be handled correctly), returning NIL is best
<beneroth> T
<beneroth> btw my code is quite often (de someFunc (param) (ifn param-check1 error (ifn param-check-2 ...))
<beneroth> (there are different ways to structure that. some make picolisp looking suddenly big - but intensive error handling / defensive programming is blowing up code in kinda all languages. some ways to structure that can also be a bit more clever and more elegant, with functions or (catch ... (throw)))....
<beneroth> it depends...
<Regenaxer> exactly
<Regenaxer> Good for the programmer. Needs to be aware what he does ;)
<beneroth> T
<beneroth> bad for the mainstream appeal ;-)
<Regenaxer> T
<beneroth> freedom is not easy. freedom is responsibility. freedom is scary.
aw- has quit [Quit: bbl]
rob_w has quit [Remote host closed the connection]
orivej has joined #picolisp
aw- has joined #picolisp
m_mans has joined #picolisp
m_mans has quit [Client Quit]
orivej has quit [Ping timeout: 240 seconds]
orivej has joined #picolisp