Day 74: Cwd and quoting constructs.

autrijus on 2005-04-15T20:55:17

Today I did minimal Pugs coding, instead mangling with #catalyst folks a bit, in my pursuit of The Way Forward with writing complex web applications for our company. It looks like the new, shiny Catalyst 5.0 is even easier to work with, and a Bamboo-Catalyst-Mason connection looks quite attractive.

Also, I caught leo on IRC, and he likes my idea of making ascii instead of iso-8859-1 as Parrot's default character set as well. Now my suggestion is in much more capable hands, I can further delay my adventure into the segfaulting land...

Pugs development continues to happen at a faster-than-a-speeding-bullet pace. I ego-googled a little bit, and it seems that several non-camelfolks have noticed our humble project: Ted from the Java/Python land, Glenn from the Lisp land, and even the great Prof. Wadler himself, who have brought innumerable advanced technologies to Haskell-land for Pugs to use.

Schwern appeared on #perl6 today, advocating the idea of a temporizable $*CWD to simplify chdir() logic:

if some_condition() {
    temp $*CWD = '/var/run/myapp';
    # ... do lots of things in that directory ...
}
# ... goes back to the original directory automagically

While he was composing his proposal to p6l, I suggested him to actually implement it in Pugs, and walked him through this implementation in a matter of minutes. Compared to implementing a new SvMG in Perl 5, that is perhaps too easy...

 $ ./pugs -e 'say $*CWD'
 /Users/schwern/devel/pugs
 woot.
 Ok, that was too easy
 now, write some test.

Because Schwern's test needs readdir(), I implemented the most simple form for him (readdir(Str) returns List), so he happily committed the test. And then there are some discussions about making all FilePath operations transparently work on URIs... But nothing concrete has ensued.

Our new committer roie has supplied a massive patch to make quoting modifiers work, so we have full access to selective interpolation now. Corion and I then proceeded to clear up some whitespace handling issues. All in all, wonderful work!

Theorbtwo is surveying the possibility of an eval_haskell() builtin in Pugs; because hs-plugins also uses the name Eval, we concluded that it may be best to rename all Pugs modules into Pugs.Eval, Pugs.AST etc.

On the cookbook front, gcomnz has written a massive introduction on the 01strings section, detailing the relevant Synopsis chunks with useful examples.

There are other, less-massive changes as well:

  • andras checked in UTF-8 URL encoding support for CGI.pm, with some tests as well.
  • iblech found lots of corner cases in map and hash/list subscript contexts, and added the test fo them.
  • corion fixed a LWP::Simple test, changed filename of fp-p6, failing pugs --version tests, among many other things.
  • ninereason highlighted the bug of assigning to negative array indices, which I hope to fix before the 6.2.1 release.
  • nothingmuch and corion refactored a lot of config header generation logic in Pugs's build system, allowing the user to set flags in $ENV{GHC}.
  • ovid added to HTML::Entities the ability to specify one's own character class to encode/decode.
  • I dropped the rx:p5 adverb; the other three notations, rx:P5, rx:Perl5 and rx:perl5, are all recognized.
  • I also implemented the want() function in its string context form.

See you tomorrow!


I can't get to the implementation

btilly on 2005-04-16T00:04:38

A dnslookup on wagner.elixus.org is failing, it looks like ns2.elixus.org and ns1.elixus.org are both timing out. :-(

Re:I can't get to the implementation

autrijus on 2005-04-16T08:31:46

Weird, it works for me... Anyway here it is.
----------------------------------------------------------------------
r13201 (orig r1987):  schwern | 2005-04-15 18:39:03 +0800

First stab at $*CWD

----------------------------------------------------------------------
=== mirror/pugs/src/AST.hs
======================================================== ==========
--- mirror/pugs/src/AST.hs  (revision 13200)
+++ mirror/pugs/src/AST.hs  (revision 13201)
@@ -1091,6 +1091,15 @@
     fetch = return . maybe undef id
     store _ v = retConstError v

+instance Scalar.Class IScalarCwd where
+    iType _ = "Scalar::Cwd"
+    fetch _ = do
+        str <- liftIO $ getCurrentDirectory
+    return $ VStr str
+    store _ val = do
+        str <- fromVal val
+    liftIO $ setCurrentDirectory str
+
instance Scalar.Class VScalar where
     iType _ = "Scalar::Const"
     fetch = return
@@ -1122,6 +1131,7 @@
type IScalar = IORef Val
type ICode   = IORef VCode
data IHashEnv deriving (Typeable) -- phantom types! fun!
+data IScalarCwd deriving (Typeable) -- phantom types! fun!
type IScalarProxy = (Eval VScalar, (VScalar -> Eval ()))
type IScalarLazy = Maybe VScalar

=== mirror/pugs/src/Run.hs
======================================================== ==========
--- mirror/pugs/src/Run.hs  (revision 13200)
+++ mirror/pugs/src/Run.hs  (revision 13201)
@@ -102,6 +102,7 @@
         , SymVar SGlobal "$!"           $ MkRef errSV
         , SymVar SGlobal "$/"           $ MkRef matchAV
         , SymVar SGlobal "%*ENV"        $ hashRef (undefined :: IHashEnv)
+    , SymVar SGlobal "$*CWD"        $ scalarRef (undefined :: IScalarCwd)
         -- XXX What would this even do?
         -- , SymVar SGlobal "%=POD"        (Val . VHash $ emptyHV)
         , SymVar SGlobal "@=POD"        $ MkRef $ constArray []
=== mirror/pugs/t/unspecced/cwd.t
================================================= =================
--- mirror/pugs/t/unspecced/cwd.t  (revision 13200)
+++ mirror/pugs/t/unspecced/cwd.t  (revision 13201)
@@ -0,0 +1,14 @@
+#!/usr/bin/pugs
+
+use v6;
+require Test;
+
+plan 2;
+
+ok( grep { $_ eq 'LICENSE' }, readdir $*CWD );
+$*CWD ~= 't/unspecced';
+ok( grep { $_ eq 'cwd.t' }, readdir $*CWD );
+
+
+skip("error handling not implemented");
+#is( ($*CWD = 'I/do/not/exist'), undef );