freenode/#lisp - IRC Chatlog
Search
15:01:55
gjvc
could someone point me at an example for reading very simple (not deeply nested) xml from a stream (file on disk) and dumping the resulting lisp form (total beginner here)
15:05:02
beach
gjvc: I would imagine the technique would be recursive descent, and similar to the code in a different language.
15:09:41
p_l
gjvc: I'd recommend using cxml, and maybe for actually doing something with the data, cxml-stp as it gives a nice recursive interface
15:12:22
moldybits`
why cxml, btw? it's easy to find a list of xml libraries, but it's hard to tell them apart.
15:13:09
p_l
moldybits`: it had pretty complete XML support, and it has cxml-stp as well as other (dom, etc) interfaces, plus a bunch of other code (I think xuriella xpath library works with it)
15:13:30
p_l
I'm aware of newer libraries, but for me cxml is kinda "tried and trusted" solution I take first when it comes to xml
15:14:38
moldybits`
i couldn't figure out how to specify the path to the dtd in cxml, so i ended up using plump which supposedly is more "lenient". (note: i'm a complete newbie wrt to xml)
15:16:23
p_l
(XML Schema isn't, and I find it superior in its limitations on what could be done with schema)
15:37:08
p_l
either I parsed XML differently in the past (lost source :( ) or I forgot how I specified dtd
15:39:11
p_l
had to download the dtd to home directory, but got this to pretty much output me a serialized form in S-expressions:
16:26:27
jgkamat
In case anyone was curious to my question yesterday, you need to have ps:lisp return a valid ps string, so (ps:lisp (push 'list my-list)) works for lists
17:31:39
p_l
my example included loading the DTD for apparently CXML didn't deal well with HTTP URIs in DTD specs
17:33:45
gjvc
yep got that and all working instaling into a project-local .quicklisp/ directory -- it's very neat
17:34:17
gjvc
i also have sbcl running via a bash wrapper to read the project-local sbcl initialisation file to make it take note of said project-local .quicklisp/ directory
17:39:05
gjvc
I have no interest in bootstrapping from them every run, given that the data is so simple
17:40:00
gjvc
but this is a more educational approach that just doing a big search and replace. (although i could write something in python to read the xml and emit lisp hmmm ...:-))
17:40:25
p_l
gjvc: then I think STP might offer a simple interface to rewrite them into whatever you want (it provides something akin to recursive descent where you plug your functions using STP methods to do things)
17:53:15
rumbler31
ok, I'm too dumb for this apparently. I want to generate and write a very long string to a file, constructed letter by letter. (dotimes (i large) (write #\E)) writes #\E, I am looking for the character itself to be read without the #\. Various attempts have failed. I suppose I could just use (format... but I'd like to learn what is going on here
17:54:31
rumbler31
assumption that was false is that I need to print pretty. that doesn't change the output unless I invoked it wrong
17:55:19
rumbler31
I assume that #\ is necessary for the reader to treat the form as a character and not a sybmol
17:57:00
pmai
FWIW write is very flexible, you can specify what you want using the keyword args or through the normal printer variables
17:57:52
rumbler31
write-char... of course. Also fwiw I was having a hard time understanding how the various flags to write relate to make thi shappen
18:38:02
p_l
Generally, for top-level variables: defvar, defparameter (the latter will always overwrite current value when evaluated), for constants use defconstant
18:38:34
p_l
mind you, defvar and defparameter will create dynamic variables, not lexical, but lexical top-level is a bit iffy
18:40:53
p_l
vms14: why do you need them in one form? It doesn't change things in the end, except for unexpected breakage from SETQ use
18:43:35
pjb
ggole_: (write foo :array t :base 10 :case :upcase :circle nil :escape nil :gensym t :length nil :level nil :lines nil :miser-width nil :pretty nil :radix nil :readably nil)
18:44:09
pjb
ggole_: of course, you can use ~A or ~S or princ or prin1 which pass the right key arguments to write.
18:45:37
p_l
vms14: because the general consensus was that assignment should not create new variables where there none
18:48:00
p_l
vms14: I tend to use DEFPARAMETER for things that I pre-set to some value, and include documentation on them (which it allows) which makes it simpler to understand the code the next day
18:48:47
p_l
i.e. it's much easier (IMO) to reason about a bunch of DEFVAR/DEFPARAMETER/DEFCONSTANT, especially when they include documentation, than any single SETQ anywhere in code
18:56:01
p_l
pjb: but the projects that insist on C either insist on it for the rare good reason (work on kernel code base in C) or can be safely ignored
18:56:27
p_l
projects that insist on language in my experience mostly involved corporate wanting java or similar :/
18:56:49
p_l
if you are the side signing the contract for the application, though, you can usually get any language going
18:57:42
p_l
vms14: and for good reasons implementations don't implement their own random object file linkers :)
18:58:03
p_l
(nothing stops you from doing one, though you would probably have to use less nice sides of FFI)
19:05:23
pjb
filename is already a pathname designator, you you don't need to call pathname on it, open will do it.
19:07:37
pjb
(with-open-file (stream filename :element-type '(unsigned-byte 8)) (cxml:parse stream handler))
19:13:27
_death
if filename is a string, then you likely want to use uiop:parse-native-namestring because otherwise each lisp implementation defines its own namestring format...
19:13:27
minion
_death, memo from flip214: I've got a couple of (old!) patches up at github.com/phmarek/dbus.git ... Would you please take a
19:18:47
pjb
vms14: (macroexpand-1 '(with-open-file (stream filename :element-type '(unsigned-byte 8)) (cxml:parse stream handler))) #| --> (let (#1=#:g37601 #2=#:g37602) (unwind-protect (multiple-value-prog1 (let ((stream (setq #1# (open filename :element-type '(unsigned-byte 8))))) (cxml:parse stream handler)) (setq #2# t)) (when #1# (close #1# :abort (null #2#))))) ; t |#
19:19:25
pjb
vms14: at home, try: (pprint (macroexpand-1 '(with-open-file (stream filename :element-type '(unsigned-byte 8)) (cxml:parse stream handler))))
19:27:36
vms14
I guess people usually don't mind in have features like what lisp offer and they look for something more mainstream
19:28:02
vms14
but when they have like 10 years of programming experience they'll be making complex systems
19:29:45
vms14
the problem is the programmer usually won't likely switch to lisp when he has 10+ years coding in somelanguage
19:33:31
LdBeth
It’s funny cause no other language use different implementations for development and deployment
19:35:12
vms14
(The bug was reported to SBCL maintainers, and there was a fix there as well, but we are still running with this hack, just to be sure :)
19:38:49
vms14
I think also we should make more documentation and maybe focus on noob friendly users
19:39:56
pjb
vms14: the essence of lisp is that you don't have a code syntax. The S-exp are defined to describe data.
19:40:01
vms14
for example the fact that python is one of the most recommended languages for a newcomer makes grow a lot its number of users
19:40:53
pjb
vms14: already, notice that there's no symbol data type in C to represent identifiers in data!
19:47:28
pjb
vms14: you still need symbols. Only Ruby has them, but with the awkward syntax of prefixing them with a colon.
19:50:19
aeth
vms14: Games probably have a better chance at being graphical applications using Lisp than traditional graphics applications because games don't have the expectation of native look and feel.
19:51:29
aeth
#lispgames is pretty active, and you have e.g. https://www.youtube.com/playlist?list=PL2VAYZE_4wRITJBv6saaKouj4sWSG1FcS
19:51:55
pjb
The essential feature is not homoiconity, it's to use the data syntax to represent code.
19:56:58
pjb
And you don't always need graphics: http://informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/sudoku-solver/index.html http://informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/rpsls/index.html http://informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/playtomo-stonedge/index.html
20:00:44
pjb
vms14: have a look at: https://cliki.net/Graphics%20library https://cliki.net/GUI I would advise https://cliki.net/pgl to write simple graphical games easily.
20:02:39
vms14
yeah, I had a look on what graphics libraries has cl, but ignored them because I know a bit of xlib, so I'd like to go for clx
20:06:41
vms14
but is nice to see this stuff, or at least to know that X was intended to be used mostly remotely
20:06:51
pjb
vms14: you don't need to know all of the condition system to use conditions. (handler-case (foo (error "an error occured")) (error (err) (print err))) is the basics of conditions.
20:06:58
Josh_2
yeh its all very annoying when you can just make a game using opengl where there are more tutorials than there are opengl programmers
20:07:18
_death
if you want to write xlib code, instead of writing a game you can have lisp play a game.. http://vito.sdf.org/dino.html
20:07:20
pjb
vms14: you don't need to know all of the format function to use format. (format stream "foo ~A bar ~S baz~%" a b) is the basics of format.
20:08:45
vms14
like appending to fill pointers, or iterating throught format arguments with things like ~:*
20:10:55
vms14
I don't know how to implement things yet, not meaning lisp, for programming in general
20:13:17
Josh_2
vms14: you just gotta find something you enjoy and just make stuff around that topic which I assume you are already doing
20:14:34
Josh_2
vms14: can you figure out how to send a button press event for me while you are at it xD
20:15:03
Josh_2
vms14: SBCL is very fast if you make declarations and use good datastructures etc, but clx is a cffi library basically so types are already known
20:49:34
jackdaniel
is there any rule in the standard how ratio should be converted to float wrt rounding? i.e is rounding to 0 correct?
21:49:30
pjb
You might want to compute the intersection of the shapes to remove it from the total area.
21:50:10
sjl
nai: ''nil reads as (quote (quote nil)), which evaluates to the list (quote nil). The cdr of that list is (nil).
21:52:52
sjl
It reads as a cons where the first element is the symbol programming and the second element is the cons itself, yeah
21:54:40
pjb
nai: it allows to create data structure where a substructure is referenced twice or more.
21:55:11
pjb
nai: in this case, we have #1# in the last cdr position, so it loops back to the first element, thus making a circular list.
21:55:24
_death
nai: https://gist.github.com/death/8c17afbba1eb10872e3c7f6f0bb7ba0a though it contains a bit of.. profanity..
21:55:45
pjb
So when printing, you get an infinite list of programmable programmable programmable … programmable programming language.
21:55:47
LdBeth
Interestingly, dispatch macro accepts a numeric arg but only a few utilizations of it
21:56:38
nai
i started trying to read LoL yesterday but then i realised my knowledge of lisp was wayyy insufficient. so here i am learning basic lisp
21:56:57
pjb
## and #= can be used to all kinds of data structure, as long as they have a readable syntax.
22:01:53
sjl
I have *print-level* and *print-length* set to big-but-finite values in my init files to prevent accidents
22:02:20
nai
i was looking at "big-but-finite" for a second like it was a lisp special value or something
22:02:44
pjb
(maplist (lambda (x) (cons x (car x))) '(a b c d e f)) #| --> (((a . #1=(b . #2=(c . #3=(d . #4=(e . #5=(f)))))) . a) (#1# . b) (#2# . c) (#3# . d) (#4# . e) (#5# . f)) |#
22:03:17
pjb
nai: because code must not contain circularity (and even shared structures). Only data (including literal data, as quoted) can have them.
22:03:54
pjb
The behavior of #1=#(#1#) may be surprising: the implementation could choose to send a missile in the general direction of your house.
22:10:22
sjl
> [special case about load-time-value described] This can happen both when an expression being evaluated or compiled shares substructure,
22:11:08
sjl
Seems to point at sharing substructure being okay. Can you be more specific about where the standard prohibits it?
22:15:00
pjb
There may be other problems, such as if the implementation provides source location, associating it with the lisp object. If it's shared, it can look as if the same lisp object has several source locations, but the implementation may be not prepared to deal with that case.
22:17:02
nai
+ seems to be the last thing i typed, * the last result i got, / the last result wrapped in ()
22:31:08
aeth
_death: At that point, just use LOOP or write your own macro on top of DO (I've done both) to avoid the repetition of the read
22:59:48
loli
It has been fun hacking package(module) functors into CL, the package system isn't the greatest so it has been a pain to do, but you can get some decent results
23:01:11
aeth
_death: imo it's a flaw in the code to use reader features when a defmacro can work instead
23:06:15
_death
aeth: the expansion of TWICE with a cons form also demonstrates structure sharing in code.. if you mean to discuss the style aspect of the DO idiom, I would tend to agree
23:10:31
_death
in your .emacs you can then have something like (setq common-lisp-hyperspec-root "file:///home/death/dev/HyperSpec/")