Arc Forumnew | comments | leaders | submit | jsgrahamus's commentslogin
2 points by jsgrahamus 1 day ago | link | parent | on: ASK: is arc used in production?

On a related note, what would motivate someone to use arc for a project instead of another language?

reply


What is dynamic-wind and why is it important?

Thanks, Steve

reply

4 points by rocketnia 35 days ago | link

Are you familiar with continuations? Continuations are essentially snapshots of the call stack. By calling (ccc ...), you take a snapshot. By calling the snapshot with a value, you jump back to that old stack -- right at the position of the (cc ...) call -- and return a different return value than before.

This is a pretty weird behavior, but it can useful for avoiding the inversion of control dilemma in imperative code. That is, if code A and B need to communicate, should code A call code B, or should code B call code A? Sometimes the callee side becomes a mess of callbacks, rather than a direct imperative style. With continuations, both sides can be the caller, and neither side needs to be the callee: When A calls B with a value, we resume B's earlier call to A using that value as the result. This approach doesn't make it straightforward to design communication paths that work like this, but it is a building block.

Unfortunately, jumping around with continuations messes up another common imperative coding technique. If people write code to set up and tear down a resource, they often like to write all the code in the middle in a way that assumes that resource is already available. With continuations, that assumption can be incorrect: If you jump out of the code in the middle, you may have just skipped the tear-down code entirely. If you jump into the middle, you may have just skipped the setup code.

Dynamic-wind makes up for that shortcoming by letting you write a structured code block that always executes its setup and tear-down sections, even if it's entered or exited using a continuation jump. So when you do a jump, you might actually go through a few dynamic-wind handlers before you reach your destination.

If you're more familiar with exceptions, continuations and dynamic-wind can be seen as a companion of exceptions and "try { ... } finally { ... }" blocks. An exception throw is a jump to an outer level of the stack, but the jump may stop to execute a few "finally" sections before it reaches its destination.

In Arc (and Scheme), continuations and exceptions are supported in the same language. They're both the same kind of jump, executing all the same handlers in between; the "finally" handlers and "tear-down" handlers are basically the same kind of handler. In Arc, unless you write custom Racket code to invoke Racket's dynamic-wind directly, Arc has no way to write a setup handler, but there is an (after ...) construct for writing a finally/tear-down handler.

I think what I've called "setup" and "tear-down" are more commonly called winding and unwinding handlers, or before and after sections. I picked the terms "setup" and "tear-down" just in the hopes of painting a more concrete picture of why they're useful.

This has still been a pretty quick explanation relative to the complexity of the topic, and I haven't included even a single example. If you still have unresolved questions, that's absolutely understandable. :)

reply

2 points by jsgrahamus 33 days ago | link

Thank you.

reply

1 point by jsgrahamus 38 days ago | link | parent | on: Using Arc at work

This is the line of code above slightly modified

  KILL ARR FOR I=1:1 READ !,X:5 QUIT:'$TEST  SET ARR(I)=X
(Press Shift-Insert or Ctr-V or whatever to insert buffer)

  PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG
           N ARR,FND,I,RSD,RTN,STOP,TXT
           W !!,"PASTE"
           F  R !,X:15 Q:'$T  S ARR($I(ARR))=X
           K RSDS
           S STOP=0,I=1 F  S RTN=$P(ARR(I),".") D  Q:STOP
           . F  S I=$O(ARR(I)) S:I="" STOP=1 Q:STOP  Q:ARR(I)?1.AN1".".E  D
           . . S TXT=ARR(I),FND=$F(TXT,"RSD ")
           . . I FND D
           . . . S RSD=$P($E(TXT,FND,999)," ")
           . . . S RSDS(RSD,RTN_"^"_$P(TXT,"+"))=""
           W !!
           S RSD=""
           F  S RSD=$O(RSDS(RSD)) Q:RSD=""  D
           . W !!,RSD
           . S RTN=""
           . F  S RTN=$O(RSDS(RSD,RTN)) Q:RTN=""  D
           . . W !?5,RTN
           Q
           ;
  FIND     ;
           N CTR,I,RTN,STR,TAG,TXT
           R !!,"STRING: ",STR Q:STR=""
           R !,"ROUTINE: ",RTN Q:RTN=""
           F I=1:1 S TXT=$T(+I^@RTN) Q:TXT=""  D
           . I TXT?1(1AN,1"%").E D
           . . S TAG=$P($P($P(TXT," "),$C(9)),"("),CTR=0
           . E  D
           . . S CTR=CTR+1
           . I TXT[STR W !,TAG W:CTR "+",CTR W ?14,TXT
           Q
           ;
Entering the next line will show the contents of the array:

  ZWRITE ARR

  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"
  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"
  ARR(3)="         W !!,"PASTE""
  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"
  ARR(5)="         K RSDS"
  ARR(6)="         S STOP=0,I=1 F  S RTN=$P(ARR(I),".") D  Q:STOP"
  ARR(7)="         . F  S I=$O(ARR(I)) S:I="" STOP=1 Q:STOP  Q:ARR(I)?1.AN1".".E  D"
  ARR(8)="         . . S TXT=ARR(I),FND=$F(TXT,"RSD ")"
  ARR(9)="         . . I FND D"
  ARR(10)="         . . . S RSD=$P($E(TXT,FND,999)," ")"
  ARR(11)="         . . . S RSDS(RSD,RTN_"^"_$P(TXT,"+"))="""
  ARR(12)="         W !!"
  ARR(13)="         S RSD="""
  ARR(14)="         F  S RSD=$O(RSDS(RSD)) Q:RSD=""  D"
  ARR(15)="         . W !!,RSD"
  ARR(16)="         . S RTN="""
  ARR(17)="         . F  S RTN=$O(RSDS(RSD,RTN)) Q:RTN=""  D"
  ARR(18)="         . . W !?5,RTN"
  ARR(19)="         Q"
  ARR(20)="         ;"
  ARR(21)="FIND     ;"
  ARR(22)="         N CTR,I,RTN,STR,TAG,TXT"
  ARR(23)="         R !!,"STRING: ",STR Q:STR="""
  ARR(24)="         R !,"ROUTINE: ",RTN Q:RTN="""
  ARR(25)="         F I=1:1 S TXT=$T(+I^@RTN) Q:TXT=""  D"
  ARR(26)="         . I TXT?1(1AN,1"%").E D"
  ARR(27)="         . . S TAG=$P($P($P(TXT," "),$C(9)),"("),CTR=0"
  ARR(28)="         . E  D"
  ARR(29)="         . . S CTR=CTR+1"
  ARR(30)="         . I TXT[STR W !,TAG W:CTR "+",CTR W ?14,TXT"
  ARR(31)="         Q"
  ARR(32)="         ;"
This is the functionality I wish to clone. Doesn't amtter to me if lists are used instead of arrays.

reply

2 points by akkartik 38 days ago | link

I'm still not following what your program does. (Can you describe its inputs and how it transforms them in english?)

I remember you asked a similar question last year: http://arclanguage.org/item?id=19109. Perhaps it would help to connect up how your question here relates to that thread?

Here's how you run the code in that thread for reading lines from a file with anarki:

  $ cat x
  ab
  cd ef
  ghi

  $ cat x.arc 
  (write:w/infile file "x"
    (drain (readline file)))

  $ ./arc x.arc
  ("ab" "cd ef" "ghi")
  #t

reply

2 points by jsgrahamus 38 days ago | link

The program will read lines of data from stdin and print each of them.

Thanks for the reminder.

How does one do, what you posted, when the input is from the keyboard buffer and not from a file?

reply

1 point by akkartik 38 days ago | link

Great! Then you should be able to drop the outer w/infile form and just say:

  (drain (readline stdin))

reply

2 points by jsgrahamus 38 days ago | link

  Error: "read-char: expects argument of type <input-port>; given #<procedure:current-input-port>"

reply

1 point by akkartik 38 days ago | link

Sorry, typed that out on my phone without trying it out. You need parens around stdin.

  (drain (readline (stdin)))
Alternatively:

  (write:drain:readline:stdin)

reply

2 points by jsgrahamus 38 days ago | link

  Unknown or expired link.
In the example above the READ X:5 or 15, allowed the read 5 or 15 seconds before timing out. I wonder if that is what we are seeing here.

Thanks for the help.

reply

2 points by jsgrahamus 38 days ago | link

Here is a follow on problem as I'm going through the tutorial: obj does not work and the error message seems to access memory not involved with the obj.

  arc> (printlst alist)

  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"



  ""
  arc> (= codes (obj "Boston" 'bos "San Francisco" 'sfo "Paris" 'cdg))
  Error: "list-ref: contract violation\n  expected: exact-nonnegative-integer?\n  given: '(((codes (obj \"Boston\" (quote bos . nil) \"San Francisco\" (quote sfo . nil) \"Paris\" (quote cdg . nil) . nil) . nil) . nil))\n  argument position: 2nd\n  other arguments...:\n   '(\"\\nARR(1)=\\\"PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG\\\"\" \"\\nARR(2)=\\\"         N ARR,FND,I,RSD,RTN,STOP,TXT\\\"\" \"\\nARR(3)=\\\"         W !!,\\\"PASTE\\\"\\\"\" \"\\nARR(4)=\\\"         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X\\\"\" \"\\nARR(5)=\\\"         K RSDS\\..."
  arc>

reply

2 points by rocketnia 37 days ago | link

Judging by that error message, it looks like the variable "=" or one of its dependencies might have been reassigned somewhere along the line. The second argument in that error message indicates that = is getting hold of your read-in data somehow, so it might be something you've defined for processing this data.

The dependencies of = include expand=list, expand=, map, pair, and setforms (among others), so if any of these has been overwritten, it might do something like what you're seeing.

By the way, I think if you're not using Anarki, there's a known bug in (readline ...) where it will spuriously combine each empty line with the following line (https://sites.google.com/site/arclanguagewiki/arc-3_1/known-...). Maybe this could explain the extra \n you're getting.

reply

2 points by jsgrahamus 37 days ago | link

Thank you.

reply

2 points by jsgrahamus 38 days ago | link

Followon #2

Stopped arc and restarted it and had no problems with obj

How prone is arc to memory problems?

reply

1 point by akkartik 37 days ago | link

Hmm, not sure what happened. Not sure what you mean by memory problems, but I've never seen flakiness in a session this short. Perhaps something in your earlier session was accidentally a control character or something. Keep an eye out for it and I will too.

Here's a full session I tried out on linux:

  $ arc
  arc> (def printlst (thelist) (if (is thelist nil) (prn "") (do (prn (car thelist)) (printlst (cdr thelist)))))
  #<procedure: printlst>
  arc> (def readit () (drain (readline (stdin))))
  #<procedure: readit>
  arc> (= alist (readit))
  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"
  ("" "ARR(1)=\"PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG\"" "" "ARR(2)=\"         N ARR,FND,I,RSD,RTN,STOP,TXT\"" "" "ARR(3)=\"         W !!,\"PASTE\"\"" "" "ARR(4)=\"         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X\"" "" "ARR(5)=\"         K RSDS\"")
  arc> (printlst alist)

  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"

  ""
  arc> (= codes (obj "Boston" 'bos "San Francisco" 'sfo "Paris" 'cdg))
  #hash(("Boston" . bos) ("Paris" . cdg) ("San Francisco" . sfo))
  arc>

reply

2 points by jsgrahamus 37 days ago | link

Thanks. Not sure what happened.

reply

1 point by akkartik 38 days ago | link

I don't follow. You got this message when you tried my code snippet? That seems really strange!

reply

2 points by jsgrahamus 38 days ago | link

Perhaps it was because I was using tryarc.org?

So I tried again with arc running on Racket under Linux. Here's what I found:

  arc> (def readit () (drain (readline (stdin))))
  #<procedure: readit>
  arc> (readit)
  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"

  ("\nARR(1)=\"PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG\"" "\nARR(2)=\"         N ARR,FND,I,RSD,RTN,STOP,TXT\"" "\nARR(3)=\"         W !!,\"PASTE\"\"" "\nARR(4)=\"         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X\"" "\nARR(5)=\"         K RSDS\"" "\n")
  arc> (= alist (readit))
  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"

  ("\nARR(1)=\"PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG\"" "\nARR(2)=\"         N ARR,FND,I,RSD,RTN,STOP,TXT\"" "\nARR(3)=\"         W !!,\"PASTE\"\"" "\nARR(4)=\"         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X\"" "\nARR(5)=\"         K RSDS\"" "\n")
  arc> alist
  ("\nARR(1)=\"PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG\"" "\nARR(2)=\"         N ARR,FND,I,RSD,RTN,STOP,TXT\"" "\nARR(3)=\"         W !!,\"PASTE\"\"" "\nARR(4)=\"         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X\"" "\nARR(5)=\"         K RSDS\"" "\n")
  arc> (len alist)
  6
  arc> (def printlst (thelist) (if (is thelist nil) (prn "") (do (prn (car thelist)) (printlst (cdr thelist)))))
  #<procedure: printlst>
  arc> (printlst alist)

  ARR(1)="PARSE    ; PARSE OUTPUT OF ^%RFIND INTO RSD/RTN/TAG"

  ARR(2)="         N ARR,FND,I,RSD,RTN,STOP,TXT"

  ARR(3)="         W !!,"PASTE""

  ARR(4)="         F  R !,X:15 Q:'$T  S ARR($I(ARR))=X"

  ARR(5)="         K RSDS"



  ""
  arc>                                                   
I think the issue with the \n is sending data between Windows and Linux.

I did have to key in Ctrl-D twice to actually get the function to finish reading. Is there a better way to do this?

Thanks for all of the help with this.

Steve

reply

2 points by akkartik 37 days ago | link

Ah, yes tryarc would explain it.

By "the issue with the \n" do you mean how each line has a \n at the start? How is this sending data between Windows and Linux, can you elaborate?

Yes, it's weird that you had to hit ctrl-d twice. Thanks. I'll try your example on windows later today.

Both these issues aren't happening for me on linux, so it seems likely to be a windows issue.

Edit: Hmm, I do see a leading empty list at the start when reading stdin:

  arc> (readit)
  abc
  def
  ("" "abc" "def")
It looks like stdin doesn't behave quite like a regular file handle.. Thanks for the report! I'll investigate why this is happening.

Edit 2: The trouble seems to be that the first call to 'readline' receives the 'enter' you hit to type in the command.

  arc> (readline (stdin))
  ""
  arc>
I think your examples might work if you put the code into a .arc file and try to run it like my original example..

reply

2 points by jsgrahamus 37 days ago | link

This probably seems weird, but I capture the data on a Windows system, then e-mail the data to a Linux system which is where arc resides. I assume Windows and Linux have different line endings.

Perhaps I need to check out the community version of arc?

Has anyone figured out a way to compile an arc routine? I saw an earlier thread on it, but no resolution.

Thanks for everything.

reply

3 points by jsgrahamus 227 days ago | link | parent | on: Automatic bug repair

Interesting article. Will the next step be computers writing their own programs?

-----


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 334 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 334 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 334 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 334 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 334 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 333 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 334 days ago | link

BTW, this is Windows 7x64.

I am pasting the definition into the arc cmd window.

-----

2 points by rocketnia 334 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 334 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 334 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 334 days ago | link

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

-----

1 point by akkartik 334 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 334 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 334 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 334 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 334 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 334 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 333 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 334 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 352 days ago | link

Rest arg :)

-----

2 points by jsgrahamus 351 days ago | link

???

-----

3 points by akkartik 351 days ago | link

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

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

-----

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

lojic - What did you end up using Racket for?

-----

3 points by lojic 389 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 391 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 400 days ago | link

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

-----

More