Arc Forumnew | comments | leaders | submit | jsgrahamus's commentslogin

Well, here's reading it into a list, which is probably the next best thing.

   (= alist (w/infile file "c:/users/steve/desktop/mccf.txt" (drain (readline file))))
Thanks for all of the help.

-----

2 points by jsgrahamus 42 days ago | link

More interesting answers/questions.

From arc.arc:

  (def read ((o x (stdin)) (o eof nil))
    (if (isa x 'string) (readstring1 x eof) (sread x eof)))

  ; inconsistency between names of readfile[1] and writefile

  (def readfile (name) (w/infile s name (drain (read s))))

  (def readfile1 (name) (w/infile s name (read s)))

  (def readall (src (o eof nil))
    ((afn (i)
      (let x (read i eof)
        (if (is x eof)
            nil
            (cons x (self i)))))
     (if (isa src 'string) (instring src) src)))
===

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all (filename) \
            (w/infile file filename \
                      (drain (readline file))))
  #<procedure: read-all>
  arc> (read-all "c:Log.txt")
  Error: "|_\r|: undefined;\n cannot reference undefined identifier"
  arc> (readfile "c:Log.txt")
  (===== 11:52:29 AM ===== 11:56:49 AM ===== 12:10:19 PM ===== 12:39:31 PM ===== 1:08:54 PM ===== 1:11:19 PM ===== 2:14:21 PM ===== 2:14:33 PM ===== 12:36:29 PM ===== 5:13:08 PM ===== 9:56:43 AM ===== 2:36:16 PM ===== 4:23:45 PM ===== 2:35:41 PM)
  arc> (readfile "c:/users/steve/desktop/mccf.txt")
  Error: "c:/users/steve/desktop/mccf.txt::509: read: bad syntax `# '"
  arc> (readfile "c:\\users\\steve\\desktop\\mccf.txt")
  Error: "c:\\users\\steve\\desktop\\mccf.txt::509: read: bad syntax `# '"
  arc> (readfile1 "c:\\users\\steve\\desktop\\mccf.txt")
  DEVISC1A1:DEVVCC>D
  arc> (readall "c:\\users\\steve\\desktop\\mcc.txt")
  (c:usersstevedesktopmcc.txt)
  arc> (readall "c:/users/steve/desktop/mcc.txt")
  (c:/users/steve/desktop/mcc.txt)
  arc> (readall "c:/users/steve/desktop/mcc.txt" (o))
  Error: "_o: undefined;\n cannot reference undefined identifier"
  arc>

-----


Here are some of the results I got:

  Use (quit) to quit, (tl) to return here after an interrupt.

  arc> (def read-all (filename)
       (w/infile file filename
                 (drain (readline file))))
  #<procedure: read-all>
  arc> (read-all "c:\users\steve\desktop\mccf2.txt")
  Error: "UNKNOWN::112: read: no hex digit following \\u in string"
  arc> Error: "_ersstevedesktopmccf2: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\users\steve\desktop\iiv.txt")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\iiv.txt")")\r\nRread-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\xxx2.m3")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\mccf.scm")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\jsg.xxx")")\r\n(read-all "
  arc> #<procedure>
  arc>

-----

1 point by rocketnia 42 days ago | link

This is probably what you need:

  (read-all "c:\\users\\steve\\desktop\\mccf2.txt")
What you wrote was a string with \u, which didn't follow through with a complete Unicode escape sequence:

  (read-all "c:\users\steve\desktop\mccf2.txt")
Once the reader got to \u, it raised a parse error, and the REPL continued to process the rest of your input as a new command:

  sers\steve\desktop\mccf2.txt")
The " here started a string, and your next command was interpreted as part of that string.

  (read-all "c:\users\steve\desktop\iiv.txt")
So here we have the end of a string, followed by the symbol c:\users\steve\desktop\iiv.txt followed by the start of another string.

-----

3 points by jsgrahamus 42 days ago | link

   Use (quit) to quit, (tl) to return here after an interrupt.
   arc> (def read-all (filename)
          (w/infile file filename
                    (drain (readline file))))
   #<procedure: read-all>
   arc> (read-all "c:\\users\\steve\\desktop\\mccf2.txt")
   Error: "_R: undefined;\n cannot reference undefined identifier"
   arc> 1
   1
   arc> (read-all "c:/users/steve/desktop/mccf2.txt")
   Error: "_R: undefined;\n cannot reference undefined identifier"
   arc>

-----

2 points by jsgrahamus 42 days ago | link

  C:\Users\Steve\Desktop>type mccf.scm
  (define x)
  (call-with-input-file "c:/users/steve/desktop/mccf.txt"
    (lambda (input-port)
      (let loop ((x (read-char input-port)))
        (if (not (eof-object? x))
            (begin
              (display x)
              (loop (read-char input-port)))))))
  C:\Users\Steve\Desktop>

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all (filename)
            (w/infile file filename
                      (drain (readline file))))
  #<procedure: read-all>
  arc> (read-all "c:/users/steve/desktop/mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:/users/steve/desktop/mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\\users\\steve\\desktop\\mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc>

-----

3 points by rocketnia 42 days ago | link

I've seen this before. What's happening, somehow, is that every time you write more than one line in a definition at the REPL in a Windows prompt, a capital R is being inserted at each newline. Arc compiles this to the Racket code _R, and when Racket executes this, it can't find the _R variable.

I seem to remember I used work around this by always pasting my multi-line definitions from a text editor rather than writing them directly at the REPL.

-----

3 points by jsgrahamus 41 days ago | link

Thanks for mentioning this. Saw it in a racket repl, too. Reported it to the Racket Users list.

-----

3 points by jsgrahamus 42 days ago | link

BTW, this is Windows 7x64.

I am pasting the definition into the arc cmd window.

-----

2 points by rocketnia 42 days ago | link

Oh, sorry. Now that I test it, I realize I remembered incorrectly.

The only time I get those spurious R characters is when I paste code into the REPL and then press enter manually. I don't get them when typing multi-line definitions directly at the REPL, and I don't get them if the code I'm pasting already has a line break at the end.

So the habit I've formed is to make sure the code I'm pasting already has a line break at the end.

I notice this issue also happens on Racket 5.3.3 -- I'm a few versions behind -- and it does not happen in the REPLs for Node.js or Clojure. It's some kind of bug in Racket. (Hmm... Racket's port.c has a bunch of spaghetti code for CRLF processing. Maybe the bug's in there somewhere.)

-----

1 point by akkartik 42 days ago | link

Oh I wonder if it's a linefeed-newline thing. I know "\r" is the code for linefeed, for example..

-----

2 points by zck 42 days ago | link

As akkartik says, let's step away from the complex code, and get back to basics. Let's use dir-exists (https://arclanguage.github.io/ref/filesystem.html#dir-exists) to test out how to reference directories.

So let's just see if we can get a 't when we check the existence of C:\users

Here are the four things I'd try:

    (dir-exists "C:/users")
    (dir-exists "C://users")
    (dir-exists "C:\users")
    (dir-exists "C:\\users")
My money's on the first or last one working. (Obviously this assumes you _have_ a `C:\users` directory) I would similarly bet that you might need to capitalize the drive, even though Windows drive letters are case insensitive (https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...). So if it doesn't work with lowercase letters, try it as above.

-----

2 points by jsgrahamus 42 days ago | link

arc> (dir-exists "c:/users") "c:/users" arc> (dir-exists "c:\\users") "c:\\users"

-----

1 point by akkartik 42 days ago | link

Very strange. What arc are you using?

Can you try it without the drain, just read the first line from the file?

Edit 10 minutes later: here's a few things I would try:

  ; a relative path with no slashes/backslashes
  (read-all "mccf2.txt")
  ; inline read-all
  (w/infile file "mccf2.txt" (drain (readline file)))
  ; try reading just the first line
  (w/infile file "mccf2.txt" (readline file))

-----

2 points by jsgrahamus 42 days ago | link

This is arc 3.1

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>type log.txt
  =====   11:52:29 AM
  =====   11:56:49 AM
  =====   12:10:19 PM
  =====   12:39:31 PM
  =====   1:08:54 PM
  =====   1:11:19 PM
  =====   2:14:21 PM
  =====   2:14:33 PM
  =====   12:36:29 PM
  =====   5:13:08 PM
  =====   9:56:43 AM
  =====   2:36:16 PM
  =====   4:23:45 PM
  =====   2:35:41 PM

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>dir c:\log.txt
   Volume in drive C is TI105757W0A
   Volume Serial Number is 48C4-C0F7

   Directory of c:\

  12/17/2014  03:40 PM               271 Log.txt
                 1 File(s)            271 bytes
                 0 Dir(s)  61,392,650,240 bytes free

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all (filename)
         (w/infile file filename
                   (drain (readline file))))
  #<procedure: read-all>
    arc> (read-all "Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:/Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\\Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
arc>

-----

2 points by jsgrahamus 42 days ago | link

This seems to be onto something!

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all2 (filename)
         (w/infile file filename))
  #<procedure: read-all2>
  arc> (read-all2 "Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (w/infile file "Log.txt" (drain (readline file)))
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11:19 PM\r" "=====\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "===== \t4:23:45 PM\r" "===== \t2:35:41 PM\r")
  arc> (w/infile file "Log.txt" (readline file))
  "===== \t11:52:29 AM\r"
  arc>

-----

1 point by akkartik 42 days ago | link

So it looks like the inlined version works, but wrapping it in a function doesn't? Very strange. Paste these lines one at a time into a fresh arc session and show me what you get in response to each line.

  (w/infile file "Log.txt" (drain (readline file)))  ; just to set a baseline
  (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (drain (do1 (readline f) (prn "CCC")))))
  (foo "Log.txt")
  (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (readline f)))
  (foo "Log.txt")

-----

2 points by jsgrahamus 42 days ago | link

akkartik, here are the results.

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (w/infile file "Log.txt" (drain (readline file)))  ; just to set a baseline
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "=====\t9:56:43 AM\r" "===== \t2:36:16 PM\r" "M\r" "=====\t2:35:41 PM\r")
  arc> (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (drain (do1 (readline f) (prn "CCC")))))
  *** redefining foo
  #<procedure: foo>
  arc> (foo "Log.txt")
  AAA
  BBB
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "M\r" "===== \t2:35:41 PM\r")
  arc> (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (readline f)))
   *** redefining foo
  #<procedure: foo>
  arc> (foo "Log.txt")
  AAA
  BBB
  "===== \t11:52:29 AM\r"
  arc>

-----

1 point by akkartik 42 days ago | link

I think rocketnia has figured it out. Does rocketnia's comment http://arclanguage.org/item?id=19137 make sense? Basically you shouldn't get an error if you type in this expression character by character, but you should if you paste it into an arc session without a trailing <enter>.

  (def read-all2 (filename)
    (w/infile file filename))
(Try it out each time as before by running (read-all2 "Log.txt"))

-----

2 points by jsgrahamus 41 days ago | link

  arc> (def read-all (filename) (w/infile file filename (drain (readline file))))
  arc> (read-all "Log.txt")
("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11:19 PM\r" "=====\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "===== \t4:23:45 PM\r" "===== \t2:35:41 PM\r")

Thanks for that.

It does appear that the problem is with pasting into the repl. So, how does one hook up arc with Emacs?

Thanks to all those who chimed in with help. Great community here.

Steve

-----

1 point by jsgrahamus 42 days ago | link

It doesn't seem to deal nicely with control characters. Not sure why the rest of the results are as they are.

-----


Why does your example return (list (a)) instead of (list a)?

Steve

-----

3 points by akkartik 60 days ago | link

Rest arg :)

-----

2 points by jsgrahamus 59 days ago | link

???

-----

3 points by akkartik 59 days ago | link

  (mac test a `(list ,a))
vs

  (mac test (a) `(list ,a))
Does that help?

-----

2 points by jsgrahamus 97 days ago | link | parent | on: Interested in being an Arc tutor?

lojic - What did you end up using Racket for?

-----

3 points by lojic 97 days ago | link

I've mainly just been learning the language. Working through some tutorials, reading books/articles, coding, etc. Did a few Project Euler problems, and now I'm working through SICP.

I burned a lot of time looking for my (not "the") perfect language, and finally settled on Racket for the dynamic language and OCaml for the statically typed language.

Now I'm trying see which problems are best suited to each of them.

Clojure has a lot of good things, but I've never been able to get past the dependency on the JVM, lack of tail calls, etc., but it's pretty darn concise.

The Racket community is incredibly strong IMO.

-----

3 points by jsgrahamus 99 days ago | link | parent | on: Interested in being an Arc tutor?

https://news.ycombinator.com/item?id=8906375

-----


My Android phone gave me a security alert on the apk.

-----

2 points by c-a-smallwood 108 days ago | link

It's not signed. Feel free to compile it from source :)

-----

2 points by jsgrahamus 126 days ago | link | parent | on: OT: Contract jobs

I've been contracting for the last few years. Hope to continue.

-----

2 points by jsgrahamus 126 days ago | link | parent | on: OT: Contract jobs

Thanks.

-----

1 point by jsgrahamus 131 days ago | link | parent | on: DrRacket(Libs) and Arc

Can anyone refer me to the method of accessing the underlying mzscheme or racket functions?

Thanks, Steve

-----

1 point by akkartik 131 days ago | link

You mean in Nu? % on Nu is like $ on anarki. Does that answer your question?

-----

3 points by jsgrahamus 131 days ago | link

I didn't specify. Could you give an example in each of them? Thanks, Steve

-----

2 points by akkartik 131 days ago | link

To call racket functions in anarki:

  arc> ($.pair? '(1))
  #t
In Nu:

  > (%.pair? '(1))
  #t

-----

2 points by jsgrahamus 130 days ago | link

Thanks, Akkartik. Is there a way to do such from arc itself?

-----

1 point by akkartik 130 days ago | link

No, you'll have to add it. The simplest way to do this is probably aw's original hack: http://hacks.catdancer.ws/ac.html

You'll need to add one line to ac.scm, and then:

  arc> (ac-scheme.pair? '(1))
  #t
Feel free to rename ac-scheme to $ or % if you think you'll use it often enough.

If you start using this you'll start finding the need for some of the other functions in that link, which transform data back and forth to the way racket or arc likes it. Come back and ask us more questions when you run into errors like this:

  arc> (ac-scheme.length '(1 2 3))
  Error: "length: contract violation\n  expected: list?\n  given: '(1 2 3 . nil)"

-----

3 points by Pauan 129 days ago | link

I would just like to point out that Arc/Nu is fully compatible with Arc 3.1, and it doesn't need conversions between Racket and Arc, so it's the easiest way to deal with Racket in Arc programs.

-----

2 points by jsgrahamus 145 days ago | link | parent | on: Mtl-arc - A new Arc implementation

Problem in building

  cc -o mtl-arc -std=c11 mtl-arc.c
  mtl-arc.c: In function ‘new_sym’:
  mtl-arc.c:46:2: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
    symname(result) = strdup(sym);
    ^
  mtl-arc.c:46:18: warning: assignment makes pointer from integer without a cast [enabled by default]
    symname(result) = strdup(sym);
                    ^
  mtl-arc.c: In function ‘new_string’:
  mtl-arc.c:59:20: warning: assignment makes pointer from integer without a cast [enabled by default]
    stringval(result) = strdup(string);
                      ^
  mtl-arc.c: In function ‘new_builtin’:
  mtl-arc.c:118:15: warning: assignment makes pointer from integer without a cast [enabled by default]
    help(result) = strdup(doc);
                 ^
  mtl-arc.c: In function ‘char_to_token’:
  mtl-arc.c:170:2: warning: return makes pointer from integer without a cast [enabled by default]
    return strdup(cbuf);
    ^
  mtl-arc.c: In function ‘split_string’:
  mtl-arc.c:194:20: warning: assignment makes pointer from integer without a cast [enabled by default]
      *(result + i++) = strdup(token);
                      ^
  mtl-arc.c: In function ‘buf_to_string’:
  mtl-arc.c:212:2: warning: return makes pointer from integer without a cast [enabled by default]
    return strdup(buf);
    ^
  mtl-arc.c: In function ‘read_expr’:
  mtl-arc.c:327:4: warning: passing argument 1 of ‘split_string’ makes pointer from integer without a cast [enabled by default]
      char **nums = split_string(strdup(token), '/');
      ^
  mtl-arc.c:181:8: note: expected ‘char *’ but argument is of type ‘int’
   char **split_string(char *a_str, const char a_delim) {
          ^
  /tmp/ccMru0iN.o: In function `builtin_cos':
  mtl-arc.c:(.text+0x3b0e): undefined reference to `sin'
  /tmp/ccMru0iN.o: In function `builtin_expt':
  mtl-arc.c:(.text+0x3bd2): undefined reference to `pow'
  /tmp/ccMru0iN.o: In function `builtin_log':
  mtl-arc.c:(.text+0x3c53): undefined reference to `log'
  /tmp/ccMru0iN.o: In function `builtin_rand':
  mtl-arc.c:(.text+0x3db2): undefined reference to `floor'
  /tmp/ccMru0iN.o: In function `builtin_sin':
  mtl-arc.c:(.text+0x3e46): undefined reference to `sin'
  /tmp/ccMru0iN.o: In function `builtin_sqrt':
  mtl-arc.c:(.text+0x3ec7): undefined reference to `sqrt'
  /tmp/ccMru0iN.o: In function `builtin_tan':
  mtl-arc.c:(.text+0x3f48): undefined reference to `tan'
  /tmp/ccMru0iN.o: In function `builtin_trunc':
  mtl-arc.c:(.text+0x3fc9): undefined reference to `trunc'
  collect2: error: ld returned 1 exit status
  make: *** [all] Error 1

-----

2 points by c-a-smallwood 142 days ago | link

I apologize, I must admit I am terrible at creating Makefiles... I'll make fixing it top priority.

Among other things, I recently added a prototype curly-infix reader, which has been kind of fun coding with, because it makes math bearable, and it makes certain things easier to read. Along with variable negation, it seems quite handy.

examples:

(def isa (a b) {type.a is b}) => (def isa (a b) (is (type a) b))

{caar = [car car._]} => (= caar (fn (_) (car (car _))))

{1 + 2 + 3 - 4 - 5} => (- (+ 1 2 3) 4 5)

-----

2 points by c-a-smallwood 141 days ago | link

It should build now

-----

More