Arc Forumnew | comments | leaders | submitlogin
Symbols with "/" and file manipulation
3 points by gamaralf 6404 days ago | 4 comments
Two Lisp/Arc newbie questions.

I have seen some macros/functions with a "/" in their names, like "w/link", is it a convention? What does it mean? By the way, searching in this forum I already discovered that a symbol ending with a "*" is a "global variable". :)

How to read and write files, both text and binary?



4 points by cchooper 6404 days ago | link

w/ is a convention, short for 'with'.

If you're looking for Arc documentation, then try http://practical-scheme.net/wiliki/arcxref

In particular, the kind of commands you're looking for are:

w/infile (open a file for input, execute some code, and then close it)

w/outfile (same as w/infile but for output)

readc/readb (read a character/byte from an open file)

writec/writeb (write a character/byte to an open file)

Other useful operators are readfile, writefile, drain and w/stdout. Note that most of the Arc functions related to file manipulation assume that the file you're editing is Arc code (e.g. readfile) so watch out for that. I haven't yet found an easy way to read the contents of a file into a string, but the following function works:

  (def loadtext (filename)
    (apply string (w/infile s filename (drain (readc s)))))

-----

2 points by cchooper 6404 days ago | link

Your question has inspired me to do some coding, so I've just posted this to the forum:

http://arclanguage.org/item?id=4220

-----

4 points by absz 6404 days ago | link

It's just a convention: "w/" is a standard abbreviation for "with," so it reads nicely. (The * ending is also a convention.) Arc does have some syntax, though (e.g. f1:f2 or x.y); I posted a list of all of the syntax at http://arclanguage.org/item?id=4012 , if you're curious.

I haven't done any I/O yet, but it looks like you want w/infile and w/outfile.

-----

1 point by gamaralf 6402 days ago | link

Thanks for the comments.

I found another very useful site: http://arcfn.com. Specially this page http://arcfn.com/foundation-doc.html (Arc: The Foundation)

-----