Arc Forumnew | comments | leaders | submit | thaddeus's commentslogin
3 points by thaddeus 6036 days ago | link | parent | on: Request for Bugs

Hello pg.

1. I would like pipe-from on windows to work. "dev/urandom" is a unix thing only. Also maybe a true pipe without file writing would be better?. Not being able to open a connection and hold on to it for reuse is a big road block for me (ie running sql).

2. I would like the path names for file and directory functions to work on windows. ie.e mkdir on windows does not support the "-p" command nor does it support forward slashes. I think the remove directory function also has unix only stuff.

I've noticed it mentioned on this forum (and from reading your code comments) that you use a Mac as do I at home, but I am hoping if there's support for windows right from the beginning that life will be easier for everyone later on.

Please and Thanks, T.

-----


The one signed in whom clicks submit at the repl... I'm thinking more like 2 admins at the repl.... this is a trick question right?

-----

2 points by CatDancer 6036 days ago | link

Not a trick question, I wasn't quite getting what you wanted to do.

Ok, so you could have the defop repl store the current user in a global variable which you could then access from the prompt. Which would work fine as long as you only had one person logging in as an admin at a time.

If you have more than one person logging in as an admin at a time and you want to know who you are from the prompt, it sounds like the challenge is to get the dynamic value of the user name into the scope of the eval'ed expression?

-----

2 points by thaddeus 6036 days ago | link

Yeah I tried going straight to your second idea (ouch!).

I really don't have 2 admins, but was trying to future proof it. I think I will just start with setting the global variable.

Thanks. T.

-----

2 points by CatDancer 6036 days ago | link

Right, well, notice that the repl-history*, that, and thatexpr are also global variables, and so future proofing it for multiple admins will take more work than just the eval issue.

(For getting values into the eval, one way to do it is with an MzScheme feature called parameters; I have a library to let you use those from Arc which I haven't quite finished yet).

-----

1 point by thaddeus 6052 days ago | link | parent | on: Getting Arc to run on Windows

I see 'uname' exist in the file 'arc.sh' (anarki);

I am not sure what this file is for; it has no docs or info; looks like it sets a 'uname' to 'Darwin' for mac osx machines, then runs some scripts via mzscheme ?

Since I didn't have admin rights on the machine (work) I created a shortcut that launches mzscheme with the directory path and passed in a 'start in' directory to anarki.

I do believe we have cygwin installed for other purposes.

-----

1 point by kens 6052 days ago | link

It looks like you're using the anarki-specific bash script to start arc. The script executes uname (which returns the OS) and checks if it is 'Darwin'. You could probably change `uname` to 'junk' (note backquotes changed to single quotes) to disable this check. But if you're on Windows, running the bash script seems like asking for trouble.

-----

1 point by thaddeus 6052 days ago | link

Thanks, I will give it a go.

As a note: I am not using a bash script to launch arc, I'm using a basic windows shortcut. This arc.sh file is initiating on it's own (as from eds; maybe because cygwin? in path?)

T.

-----

1 point by thaddeus 6050 days ago | link

Changing uname to 'junk', didn't work (I even deleted the file) no luck (pg's arc2 doesn't have the uname problem, but errors on other things like creating directories and loading asv).

Anyone know how to prevent anarki from thinking my windows machine is unix machine?

Thanks, T

-----

1 point by thaddeus 6050 days ago | link

Nevermind - I figured it out. I just changed the lib.arc so that ffi.arc doesn't get loaded. I hope someone who knows how to use git can put ffi into the lib folder and not have it load by default. T.

-----

2 points by thaddeus 6064 days ago | link | parent | on: Arc2.tar

What is it, about arc2, that you're having difficulty with?

-----


Hi CatDancer,

I've changed a bunch of code in json.arc, not sure if you would like me to hand over to you. there are things I have done you might think are good, some maybe bad....

* changed it to support both number types (int and num)

* changed it to output both number types as numbers, rather than strings.

* changed the function name 'alt' to 'alt-em' so that it doesn't conflict with the same function name in 'parser', thus fully co-operates with anarki.

* here's possibly a bad one: I put support in for symbols even though I know json is a public api and in itself doesnt support the concept of a symbol - it helps when I need to auto-load tables, otherwise converting a string to a table-name (type table) is a real pain. Fortunately it's optional, thus the code doesn't require it's use.

* I put in support for nested tables.

let me know if you want me to provide you with my changes at 'tcr1272 at gmail dot com' and I can then email it to you. or if you can suggest a way for me to upload it somewhere for you.

Thanks, T.

-----

1 point by CatDancer 6071 days ago | link

Very cool! I sent you an email, and also my email address is cat@catdancer.ws. I also added my email address to my profile here on arclanguage.org.

-----

1 point by rincewind 6071 days ago | link

how about you upload them to github? :-)

-----

1 point by CatDancer 6071 days ago | link

I'm using git and github as an experiment, wondering what the best way to share Arc patches might be. For myself, so far using git has felt like driving a tractor trailer to get a sandwich at the corner grocery store... big, powerful, can move an awesome amount of stuff, but clumsy... necessary when you have tens of thousands of lines of code, but when your language is high enough level that you don't need that many lines of code, is git actually useful? I don't know yet. In any case, I'm happy to get patches in any form that is convenient for the sender, whether by email, pastebin, or by github's "pull request" mechanism.

-----


I've just started to use the http-get library; one note and one question:

the note: the 'str->url' function contains a function call '1+' which doesn't work in anarki (changing (1+ port) to (+ 1 port) fixes the ability to get webpages from a local port (local8080).

the question: how can I use the 'save-page' function on a page hidden behind a defopl ? ie, how can I pass authentication in to get past the login page of someone elses arc server page?

Thanks, T.

-----

2 points by thaddeus 6083 days ago | link | parent | on: String matching

I don't have my environment up as I am at work, but it should work something like:

(find "google" '(yahoo yahoogoogle "google yahoo"))

but it looks like you need to find "google" inside a string thats inside a list:

To find a sub-string use:

    Arc>(findsubseq "google" "google yahoo")
    0
so essentially if the string "google" exists inside the other string you will get the start position returned otherwise you will get nil.

Then you could:

    (def test-string-for-sub-string (mystring thestring)
      (= result (findsubseq mystring thestring))
      (if (isnt result nil)
          (prn mystring))
    )

    Arc> (test-string-for-sub-string "google" "google yahoo")
    "google"
and then do something like:

    (def test-list-for-substring (mystring)
      (= item-list '(yahoo yahoogoogle "google yahoo"))
      (each item item-list 
            (if (isa item 'string)
                 (test-string-for-sub-string mystring item))
      )
    )
I am not suggesting this is the best way, I'm just laying it out so that you understand how the list and string functions work to achieve what you would like to do.

Like I said I don't have arc to verify what I wrote evaluates correctly, but I think its close.

Also note: I found arcfn.com to be a great resource.... you can go to:

    http://arcfn.com/doc/index.html

    then click the strings operations link:

    http://arcfn.com/doc/string.html
T.

-----

2 points by thaddeus 6083 days ago | link

and taking a second look: I also see a symbol in the list that has google in it.

If you need the symbol 'yahoogoogle to find google too, then you may want to convert each item in the list to a string then do your check?:

    (def test-list-for-substring (mystring)
      (= item-list '(yahoo yahoogoogle "google yahoo"))
      (each item item-list 
            (= string-item (tostring item))
            (test-string-for-sub-string mystring string-item))
      )
    )

-----

1 point by goolu 6083 days ago | link

I really appreciate your help. I will try this later tonight. thanks

-----

1 point by thaddeus 6083 days ago | link

no problem.

P.S.You may want to check out the function 'in'. Depends on how you're pulling the items to check against. If it's a list as you suggested then 'find', or looping through 'each' is probably the best, but if they are separate arguments 'in' may be easier. T.

-----

1 point by goolu 6083 days ago | link

awesome. second approach (tostring) worked. I tried to put your code and came up with this: (def test-list (mystring item-list) (each item item-list (if (findsubseq mystring (tostring (pr item))) (prn item)) ) )

arc> (test-list "google" '(yahoo yahoogoogle "google yahoo")) yahoogoogle google yahoo

i was trying to use car on list..but it dint worked. Thanks

-----

1 point by thaddeus 6083 days ago | link

As a note - you dont need (tostring (pr item)) ....unless you want the output of each result to be a string. you could just use (string item).

Here's another method just for the sake of learning:

This method does a few things..(which maybe good or bad).

     * it returns it in a list format for re-use.
     * it maintains the original 'type'.
     * it still preserves the original order.

    (def test-list (mystring item-list) 
         (rev (accum tolist 
	          (each item item-list 
		      (if (findsubseq mystring (string item))
			      (tolist item)))))) 


    arc> (test-list "google" '(yahoo yahoogoogle "google yahoo"))
    (yahoogoogle "google yahoo")

-----

1 point by goolu 6083 days ago | link

awesome. second approach (tostring) worked. I tried to put your code and came up with this: (def test-list (mystring item-list) (each item item-list (if (findsubseq mystring (tostring (pr item))) (prn item)) ) )

arc> (test-list "google" '(yahoo yahoogoogle "google yahoo")) yahoogoogle google yahoo

i was trying to use car on list..but it dint worked. Thanks

-----

1 point by thaddeus 6084 days ago | link | parent | on: Using SOAP in Arc ?

Thanks CatDancer.... The idea I am working is to see if I can publish a web-app from my server. And that other people can develop their own interface for it. That their interface can change data on my server using web protocols over http, so that anyone one can hook up their own interface to it and choose how much or little they need to manage.

So I believe I am saying I need to use a web service, and I am not sure what options I have for protocols.

The read and write is I can do, but how do I notify my web app that a message has been sent to it for processing ?

Thanks, T. T.

-----

3 points by CatDancer 6084 days ago | link

For a public API, JSON is a nice choice (http://json.org/), for which (ta da!) I just happen to have a reader/writer for: http://catdancer.github.com/json.html

For a nice example of a JSON web API, check out FriendFeed: http://code.google.com/p/friendfeed-api/wiki/ApiDocumentatio...

To handle an API message, you use a regular defop... what makes it a "web" API is that it uses the same HTTP protocol that a browser uses to fetch a web page or to post a form. In fact, you can often use a browser to try out a web API. For example, point your browser to http://friendfeed.com/api/feed/public, and you'll see a JSON message containing the most recent 30 public entries published to FriendFeed.

Here's an example of a very simple API written in Arc. For debugging, I have an op called "log" which will print a message in the window I'm running Arc in. So calling "http://myserver.com/log?message=hello" will print "hello" in my server window:

  (defop log req
    (eprn (arg req "message"))
    (pr "OK"))
My eprn function simply prints out to stderr, since anything printed to stdout is returned to the client.

  (def eprn args
    (w/stdout (stderr)
      (apply prn args)))
The (pr "OK") prints "OK" to stdout, which is returned to the client, so if you pointed your browser at http://myserver.com/log?message=hello you'd see "OK" displayed in your browser window.

To return JSON data like FriendFeed, you can either do it by hand:

  (defop inventory req
    (pr "{\"apples\":5,\"bananas\":18}"))
or use my JSON library:

  (defop inventory req
    (pr:tojson (obj apples 5 bananas 18)))
To have your client control your server, write a defop that takes actions depending on the arguments passed to it:

  (defop shutdown req
    (if (is (arg req "password") "xyzzy") (quit)))

-----

2 points by thaddeus 6083 days ago | link

is there a set of dependancies for json.arc ?

I run:

(pr:tojson (obj apples 5 bananas 18))

and I get:

Error: "reference to undefined identifier: __mz"

Thanks, T.

-----

2 points by thaddeus 6083 days ago | link

ugh!

Ok I found the mz patch you created, but it's a little confusing installing it.

I tried the "patch method" but obviously the command

    "patch <mz.patch"
will not work in the arc top level. i am assuming you're running mzscheme directly to run this command (which i have never done).

I tried downloading your version of arc, but it doesn't work with or sync with "anarki". I get errors.

I find the whole library part of anarki extremely confusing. As much as I am sure people are contributing valuable code, it's like it's a dumping ground with little documentation (some exceptions). People are throwing code in odd directories with odd names and no examples for usage.

wouldn't be nice to have an install like:

  /arc/required/*.arc

  /arc/recommended/patch/before/*.arc; for bug fix code that has to be loaded instead of the relative core arc or mzscheme code, as opposed to after.

  /arc/recommended/patch/after/*.arc; for bug fix code that can be loaded after core arc loads, but before libraries.

  /arc/recommended/libraries/*.arc; 

  /arc/optional/; no optional files or patch files for optional libraries to be in any 'recommended' directories.  

  /arc/optional/patch/*.arc

  /arc/optional/patch/before/*.arc

  /arc/optional/patch/after/*.arc

  /arc/optional/libraries/*.arc

oh and while i'm frustrated.... an ide with a picklist for the optionals that figures out for us what dependancies are in place and manage them.

ugh.....

:)

-----

1 point by thaddeus 6082 days ago | link

Ok,after reading many posts I found the right one; and can see people had already figured out a means to do this....

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

To date I have just been downloading the anarki directory, but tonight I'm going to try using the "git stable" method.

Question for you CatDancer, is your copy of Arc2 the equivalent of 'git stable' ?

I don't find I am using many of the optional features in anarki (so far I only use parsecomb and arcformat which are awesome) and if I do I was thinking I could drop them on top of your arc2 copy.

Thanks, T.

-----

1 point by CatDancer 6082 days ago | link

so far I only use parsecomb and ...

Were you able to get parsecomb to do anything? I was able to get it to make matches, but I couldn't figure out how to get it to tell me which match had been made. (For example, I could have it match a number or a string, but if it matched "123" I would get "123" returned to me but I couldn't figure out how to tell that it was a number that had been matched).

iirc, I ran parsecomb in pg's arc2 by removing the documentation strings from the beginning of the def's in the source.

-----

1 point by thaddeus 6082 days ago | link

Sorry. I meant 'parser'. I use it to feed code into arcformat. Let's me un-expand for presentation purposes.

T.

-----

1 point by CatDancer 6082 days ago | link

is your copy of Arc2 the equivalent of 'git stable'

My copy of Arc2 is pg's original arc2, which I got from http://arclanguage.org/install; I haven't looked at Anarki's stable branch.

-----

1 point by CatDancer 6082 days ago | link

thaddeus, I updated my documentation at http://catdancer.github.com/mz.html to give an explanation of the patch command and how to use it. Take a look and let me know if it's helpful. (Note github has come kind of caching bug with their pages so if you go back to the page your browser will display the old version of the page if it has a copy of it in its cache; you must click the refresh button or press F5 to see the new version).

I also crossed out the explanation of how to apply the patch using "git pull", since as you discovered "git pull" doesn't work if the two git repositories don't share a common ancestor. (I suspect there is a way to do this using git, but I'll have to go looking for it).

-----

1 point by thaddeus 6082 days ago | link

Looks good to me. Thank you for updating your doc.

:)

-----

1 point by CatDancer 6082 days ago | link

"patch" is actually a Unix command, it comes standard with Unix. So you'd type "patch <mz.patch" in your Unix shell, inside your arc directory.

If you're running Windows, if I remember correctly patch comes with cygwin... though I'm not sure.

If you look at mz.patch you can see that it is merely adding one line to ac.scm, so if all else fails, you can edit ac.scm and add the line yourself :-)

mz.patch is a patch against pg's original arc2... I have no idea if it will work with Anarki or not.

-----

1 point by thaddeus 6080 days ago | link

As a note for other n00bs who want to use the mz patch on anarki, it's probably best to just manually add the one line to the ac.scm file. Running the patch will fail with an error "patch already detected". I'm no unix expert but I looked at the anarki verion and there's already extra lines added where the patch expects to place it's code line(And the "add anyway" unix prompt failed for me).

At any rate I'm now playing with your json library CatDancer. Thanks for the help along the way. T.

-----

1 point by CatDancer 6080 days ago | link

I have no idea why I used ((mz integer?) v) instead of (isa v 'int) in json.arc, it sounds like it would have saved you some trouble if you hadn't needed to install the mz patch first.

-----

1 point by thaddeus 6082 days ago | link

Thank you. I will give this another go.

-----

1 point by thaddeus 6084 days ago | link

Ok, that looks like the kind of example I was looking for. Thanks!

-----


I'm assuming when you say 'standout' you mean format/indent your line breaks for code.... for that you add 4 spaces before each line of code. If you mean standout = bold, no clue. T.

-----

1 point by wgac 6108 days ago | link

Thanks.

-----


In retrospect, after doing some reading, I like the keywords concept outlined in kenny's dsb function. Although or=, works and I will use for now... in the long run I can see how having the sequence of arguments forced leading to bugs.

If I have many function calls all using an enforced sequence and for whatever reason the original function is changed (ie an inserted argument in the sequence list) all the function calls would have to be changed to accomodate.

The keyword concept also makes the code much more readable for the function calls: something like:

    (def the-example ((o car "mustang") (o year "1969") (o color "black")) 
         (prn "Car: " car)
         (prn "Year: " year)
         (prn "Color: " color)
    )
thus...

    (the-example car: camaro color: red year: 1968 )
is not only much more readable, but also the fact that I switched the order wouldn't impact the integrity of the code.

Additionally or=, prevents one from passing in nil as a valid argument...

probably stuff everyone here knows, but just my two cents!

.... actually in thinking about it.... I wonder if it was an intentional decision by pg not to put this feature in or was it just not gotten to?....

anyway - have a good night all, and thanks for the replies.

T.

-----

1 point by thaddeus 6101 days ago | link

So when I originally made this posting I was attempting to create a function that would create the style attributes within in an html div.

Since the style parameters/arguments are completely differrent for each of my divs, I found it a pain to keep doing this:

    (pr "<div " "id=")
	(write (string "divLeftBox"))  
	(pr "style=")
    (write (string "position: absolute; left: 1px; top:" 1 "px;" 
	(if (is border->toggle 1)(string "border: 1px solid #ff9000;"))
	 "width:" width "px; " "height: " height "px;"))
	(pr ">")
So I took a stab at writing a function, following, that would handle all the possible formats, but discovered the variances too ugly in coding without being able to handle the "inside optional arguments" for a function:

     (def genstyle-old (overflow position top right bottom left width width-uom height height-uom border-width border-color)
              (or= overflow 'auto)
	          (or= position 'absolute)
	          (or= top 0)
	          (or= right 0)
	          (or= bottom 0)
		      (or= left 0)
			  (or= width 100)
              (or= width-uom "%")
			  (or= height 100)
              (or= height-uom "%")
			  (or= border-width 1)
		      (= border-line-style 'solid)
			  (or= border-color "#ff9000")
              (string "overflow: " overflow ";" " position: " position ";"
                             " top: " top "px;" " right: " right "px;" " bottom: " bottom "px;" " left: " left "px;"
                             " width: " width width-uom ";" " height: " height height-uom ";" 
	                         " border: " border-width "px" " solid " border-color ";")
    )
Anyway that turned out too ugly and Kenny's dsb function was too complicated for me to figure out, so I went back and looked into how pg was doing these type of things... and came up with the following:

    (mac genfn args (genlist args))

    (def genlist (spec)
       `(tostring ,@(parg (pair spec)))
    )


    (def parg (options)
       (if (no options)
        nil
       (let ((opt val) . rest) options
            (cons (parg-it opt val)
                  (parg rest))))
    )

    (def parg-it (key val)
        `(aif ,val (pr " " ',key " " it ";"))
    )

this allows me to do this:

     (def test ()
         (= height 10) 
         (= width 20)
         (gentag div id "mydiv" style (genfn position: "absloute" overflow: "auto" width: (string width "px") height: (string height "px") padding: "2px 3px 2px 3px"))
     )
resulting in this:

    arc> (test)
    <div id="mydiv" style=" position: absloute; overflow: auto; width: 20px; height: 10px; padding: 2px 3px 2px 3px;">
* note the significance for me is that I can pull the style arguments from a table and then autogenerate the list to be passed into the genfn function based upon which attributes exist in the table; then all I would need to do is pass in the table name. The end result will be 1 function that generates all of my divs, table driven.

I figured there might be some people out there (like myself) trying to do the same thing. I don't know how to put things on "git", nor do I want to throw my "hacks" into a repository that's probably intended for better code. :)

T.

-----

More