`not' in parameter lists

Consider these two examples:
   assert not foo.bar?
   assert not foo.bar? and not baz.quux?
I don't think it would be acceptable to have the former work
as intended, while the latter would siletly misbehave.

I disagree. The order of precedence of the operators is advertised, and plenty of things fail silenty. (see duck typing)

> While I think a lisp-like syntax is immensely powerful
> from a programatic standpoint I think that it can be
> difficult for a human to read and understand quickly.

I would have to agree.

    assert ((foo.respond_to? :bar) and (plurgh.include? :mif))
Difficult to read and understand?

The problem, ultimately, is that you can't meaningfully do:

foo bar baz, moomin snufkin

Indeed. I have been schooled, yet again. OK, well I'm still hoping for LISP-with-commas. :slight_smile:

Devin

···

On Jul 17, 2005, at 2:34 PM, Daniel Brockman wrote:

This message ended up getting pretty long and off-topic,
with lots of jabbering about syntax, and ending with a
shameless plug. So read it at your own risk.

twifkak@comcast.net writes:

Consider these two examples:

   assert not foo.bar?

   assert not foo.bar? and not baz.quux?

I don't think it would be acceptable to have the former work
as intended, while the latter would siletly misbehave.

I disagree. The order of precedence of the operators is
advertised, and plenty of things fail silenty. (see duck typing)

After some consideration, I've changed my mind.

This is alledgedly confusing:

   assert not foo.bar? and not baz.quux?

But this is already allowed, and just as confusing:
   
   assert foo.bar? and not baz.quux?

As you imply, anyone who is familiar with the order of
precedence of the boolean operators will type this:
   
   assert not foo.bar? && not baz.quux?

They will not expect this to mean the same:

   assert not foo.bar? and not baz.quux?

So I'm back on track again believing that ‘not’ *should* be
allowed in parameter lists after all.

While I think a lisp-like syntax is immensely powerful
from a programatic standpoint I think that it can be
difficult for a human to read and understand quickly.

I would have to agree.

    assert ((foo.respond_to? :bar) and (plurgh.include? :mif))

Difficult to read and understand?

Not particularly, but a little. I'm not used to that style,
which I guess is why I actually consider the full-blown Lisp
syntax more readable:

   (assert (and (foo.respond_to? :bar) (plurgh.include? :mif)))

Of course, the conventional Ruby style is just as readable:

   assert foo.respond_to?(:bar) && plurgh.include?(:mif)

The real readability benefits of a Ruby-like syntax over a
Lisp-like one I think comes from the fact that where Ruby
has keywords, Lisp leaves it to positionality and list
structure to define the meaning of parts of an expression.

Compare this (I'm sorry I couldn't be bothered to come up
with a less brain-dead example)

   case
   when bar.respond-to? :moomin
     puts "snufkin"
   else
     something-or-other
   end

to this:

   (cond
    ((respond-to? bar :moomin)
     (puts "snufkin")
    (t
     (something-or-other))

I think the former (Ruby) is much more readable. But now
consider this Lisp/Ruby hybrid:

   (case
     (when (bar.respond-to? :moomin)
       (puts "snufkin")
     (else
       (something-or-other))

Pretty nice, ain't it? I think it's better than its parts.
Alas, the current Ruby parser only lets you go this far
towards Lisp,

   (case
    when (bar.respond-to? :moomin)
      (puts "snufkin")
    else
      (something-or-other) end)

which I think is insufficient, leaving you with a weird
Ruby-with-too-many-parens syntax.

The problem, ultimately, is that you can't meaningfully do:

foo bar baz, moomin snufkin

I think you mean ‘unambiguously’, not ‘meaningfully’.
Of course you can assign meaning to the above code.

Anyway, you *can* unambiguously do this:

   foo bar(baz), moomin snufkin

Therefore, I think the parentheses of a last-parameter
nested method call should be optional, analogously to the
implicit hash syntax. What I'm saying is that this

   foo bar(baz), moomin => snufkin

already means this,

   foo bar(baz), { moomin => snufkin }

so why not make this

   foo bar(baz), moomin snufkin

mean this?

   foo bar(baz), (moomin snufkin)

That'd allow the common use case of ‘foo bar baz’:

   assert foo.respond_to? :bar

Indeed. I have been schooled, yet again. OK, well I'm
still hoping for LISP-with-commas. :slight_smile:

We already have Lisp with commas, infix operators, some
miscellaneous nice syntactic constructs, no ‘QUOTE’,
optional parentheses (based on lines), mandatory ‘end’s,
arrays instead of lists, and a limited answer to macros.

Well, pretty much. If we could just leave out the ‘end’s,
we'd be pretty close[1] to getting the best out of Lisp's
syntax (except we still wouldn't have ‘QUOTE’).

Maybe you'd be interested in a preprocessor[2] that lets you
use hyphens instead of underscores? It throws in a few
additional things like allowing this

   @timers.each { .fire if .ready? }

as a shortcut for this,

   @timers.each { |t| t.fire if t.ready? }

and this

   Transfer.new ~:file-name, ~:file-size, ~:file-offset

as a shortcut for this:

   Transfer.new \
     :file-name => file-name,
     :file-size => file-size,
     :file-offset => file-offset

It also adds ‘<-’ as a synonym for ‘=’, which lets you write
things like this,

   if connection <- @socket.accept
     signal :new-connection, connection end

instead of the equivalent with an equals sign (which in this
case can't really be confused with ‘==’, thanks to context),

   if connection = @socket.accept
     signal :new-connection, connection end

(I'm still not sure whether I like this last one.)

Of course, it would be nicer if the good ones of these
features were integrated into the language, but most
probably won't, and even if some might, that'll take time.

That's not going to stop me from using them, though. :slight_smile:
The preprocessor is automatic, and doesn't get in my way.

···

On Jul 17, 2005, at 2:34 PM, Daniel Brockman wrote:

--
Daniel Brockman <daniel@brockman.se>

[1] <http://www.brockman.se/software/hyphen-ruby/long-live-the-parens.png&gt;
[2] <http://www.brockman.se/software/hyphen-ruby/hyphen-ruby.rb&gt;

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this? --TTN.

Daniel Brockman wrote:

This message ended up getting pretty long and off-topic,
with lots of jabbering about syntax, and ending with a
shameless plug. So read it at your own risk.

Yeah. Sorry, the disclaimer encouraged me to put off reading this for a day.

   assert ((foo.respond_to? :bar) and (plurgh.include? :mif))

Difficult to read and understand?
   
Not particularly, but a little. I'm not used to that style,
which I guess is why I actually consider the full-blown Lisp
syntax more readable:

  (assert (and (foo.respond_to? :bar) (plurgh.include? :mif)))

Of course, the conventional Ruby style is just as readable:

  assert foo.respond_to?(:bar) && plurgh.include?(:mif)

Yeah, my Lisp-with-commas description was always slightly tongue-in-cheek. I find (method *arguments) more readable than method(*arguments) though, especially in a nest of stuff.

Yeah, the Ruby one's alright...

  (case
    (when (bar.respond-to? :moomin)
      (puts "snufkin")
    (else
      (something-or-other))

I dunno. Unnecessary parens, IMO. Also, I don't like putting a close paren/closing tag/end keyword at the end of a line unless the open paren/open tag/begin keyword is at the beginning of the same line. That way it's easier to spot code that's missing an end-tag. (And you can't give up the end-tag unless you want significant whitespace.) Joel Spolsky has a decent piece on making wrong code *look* wrong. Of course, in it, he advocates Hungarian notation, but one can look past that to see the meat of the article... :slight_smile:

Therefore, I think the parentheses of a last-parameter
nested method call should be optional, analogously to the
implicit hash syntax.

OK, for what it's worth, I like.

Maybe you'd be interested in a preprocessor[2] that lets you
use hyphens instead of underscores?

Yeek. Preprocessors = evil! Granted, this one's written in plain Ruby, which is neat, but still. If I could just say require 'hyphen-ruby' and not __END__ at the beginning of the code...

  @timers.each { .fire if .ready? }

That's neat.

Devin
eat_program. hehe...

Hi Devin,

I find (method *arguments) more readable than
method(*arguments) though, especially in a nest of stuff.

That's interesting... Are you a long-time Lisper?

  (case
    (when (bar.respond-to? :moomin)
      (puts "snufkin")
    (else
      (something-or-other))

I dunno. Unnecessary parens, IMO. Also, I don't like
putting a close paren/closing tag/end keyword at the end
of a line unless the open paren/open tag/begin keyword is
at the beginning of the same line. That way it's easier to
spot code that's missing an end-tag.

...nope, definitely not a Lisper. :slight_smile:

(Yes, I do appreciate the irony of the fact that I missed,
not one, but *two* parens in the above snippet of code.)

(And you can't give up the end-tag unless you want
significant whitespace.)

With the risk of being denounced for a heretic, I have to
say that I wouldn't mind a flag that turned this on. :slight_smile:

I'm not particularly fond of the ‘end’ ladders, although I
do appreciate them when reading or writing code without
syntax highlighting and all the other editor features you
take for granted (like on a maling list).

Joel Spolsky has a decent piece on making wrong code
*look* wrong.

...I don't see the point. Won't this do?

   # THIS CODE IS BROKEN AND WRONG --- DO NOT USE
   # UNDER ANY CIRCUMSTANCES!

Of course, in it, he advocates Hungarian notation, but one
can look past that to see the meat of the article... :slight_smile:

I guess I'll have to dig it up. I do recall reading
something where he advocates Hungarian notation, but he
probably does that all the time. I guess you can't really
blame him though; after all, he's been exposed to God knows
how much of Microsoft's C code.

Therefore, I think the parentheses of a last-parameter
nested method call should be optional, analogously to the
implicit hash syntax.

OK, for what it's worth, I like.

What do other people think? [For those of you who didn't
follow this thread, we're talking about allowing this

   assert foo.respond_to? :bar

and this (excuse the brain-dead example)
   
   assert foo == bar, "foo!@# differs from bar".delete "!@#"

but not this,

   assert foo.respond_to? :bar, "foo doesn't respond to :bar"

because of the ambiguity.]

Maybe you'd be interested in a preprocessor[2] that lets
you use hyphens instead of underscores?

Yeek. Preprocessors = evil! Granted, this one's written in
plain Ruby, which is neat, but still.

I hear there's an independent “exprerimental” branch of Ruby
out there; I've been thinking about trying to get some of
this stuff into that... maybe as a kind of stepping stone.

If I could just say require 'hyphen-ruby' and not __END__
at the beginning of the code...

Aw, come on. You don't even need the __END__ in any other
files apart from the one that contains the main entry point.
Actually, if you write that file in vanilla Ruby, you don't
need to put __END__ *anywhere*. :slight_smile:

  @timers.each { .fire if .ready? }

That's neat.

I'm glad you like it. :slight_smile:

Devin
eat_program. hehe...

Hey, you gotta have a system metaphor. Mine is a cookie
monster that eats text instead of cookies. :slight_smile:

···

--
Daniel Brockman <daniel@brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this? --TTN.

Daniel Brockman wrote:

Joel Spolsky has a decent piece on making wrong code
*look* wrong.
   

I guess I'll have to dig it up.

Aw, come on. You don't even need the __END__ in any other
files apart from the one that contains the main entry point.
Actually, if you write that file in vanilla Ruby, you don't
need to put __END__ *anywhere*. :slight_smile:

Sorry! Maybe I'm just broken. Maybe I'll experiment with it.

Hey, you gotta have a system metaphor. Mine is a cookie
monster that eats text instead of cookies. :slight_smile:

Hrm. Haven't had a system metaphor yet. Now I know what I'm missing out on.

Devin
R is for Ruby, that's good enough for me.

Devin Mullins <twifkak@comcast.net> writes:

Joel Spolsky has a decent piece on making wrong code
*look* wrong.

I guess I'll have to dig it up.

Making Wrong Code Look Wrong – Joel on Software

Thanks! That's a great article, and I don't think I did
read it before. I'm sorry, I just have to quote a few
passages that I found particularly amusing.

   “It’s at this point you typically say, ‘Blistering
   Barnacles, we’ve got to get some consistent coding
   conventions around here!’ and you spend the next day
   writing up coding conventions for your team and the
   next six days arguing about the One True Brace Style
   and the next three weeks rewriting old code to conform
   to the One True Brace Style until a manager catches
   you and screams at you for wasting time on something
   that can never make money, and you decide that it’s
   not really a bad thing to only reformat code when you
   revisit it, so you have about half of a True Brace
   Style and pretty soon you forget all about that and
   then you can start obsessing about something else
   irrelevant to making money like replacing one kind of
   string class with another kind of string class.”

   [...]

   “Now, when I’m writing a dinky script to gather up a
   bunch of data and print it once a day, heck yeah,
   exceptions are great. I like nothing more than to
   ignore all possible wrong things that can happen and
   just wrap up the whole damn program in a big ol’
   try/catch that emails me if anything ever goes wrong.
   Exceptions are fine for quick-and-dirty code, for
   scripts, and for code that is neither mission critical
   nor life-sustaining. But if you’re writing an
   operating system, or a nuclear power plant, or the
   software to control a high speed circular saw used in
   open heart surgery, exceptions are extremely
   dangerous.”

Anyway, great as the article may be, I feel morally obliged
to include the following small note of warning.

      WARNING: There is a VERY REAL RISK that the
      aforementioned article WILL SUCCEED in turning
      you on to Hungarian notation.

Aw, come on. You don't even need the __END__ in any
other files apart from the one that contains the main
entry point. Actually, if you write that file in vanilla
Ruby, you don't need to put __END__ *anywhere*. :slight_smile:

Sorry! Maybe I'm just broken. Maybe I'll experiment
with it.

Cool! If it gives you any trouble, please let me know. :slight_smile:

Hey, you gotta have a system metaphor. Mine is a cookie
monster that eats text instead of cookies. :slight_smile:

Hrm. Haven't had a system metaphor yet. Now I know
what I'm missing out on.

Look here for more information:

   <http://c2.com/cgi/wiki?SystemMetaphor&gt;

···

--
Daniel Brockman <daniel@brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this? --TTN.

Devin Mullins wrote:

Making Wrong Code Look Wrong – Joel on Software

That article is again proof that Joel is an utter idiot,
        nikolai (who’s thinking of registering joelisfud.com)

···

--
Nikolai Weibull: now available free of charge at http://bitwi.se/\!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

Nikolai Weibull wrote:

Devin Mullins wrote:

Making Wrong Code Look Wrong – Joel on Software
   

That article is again proof that Joel is an utter idiot,
       nikolai (who’s thinking of registering joelisfud.com)

Well, I happen to think he's, like, 20% right on exceptions, and 5% right on Hungarian, but again, while the particular solution is wacky, the general solution is good, and well put: Make Wrong Code Look Wrong.

No?

Devin

Well, I happen to think he's, like, 20% right on exceptions, and 5% right on Hungarian, but again, while the particular solution is wacky, the general solution is good, and well put: Make Wrong Code Look Wrong.

I read it and thought that the idea that the original idea was to prefix the semantic meaning, not the type was actually not a bad idea, but so many developers (windows developers) prefix with useless stuff like iValue (int) etc, that I came to the conclusion there was no usefulness in prefix notations. Also I was taught to give meaningful variable names anyway so his examples wouldn't have counted with my variable naming conventions.

A lot of people are looking at Exceptions as an ugly step-sister these days - I think Bruce Eckel made a similar point (hence the Thinking in Python book)

Kev

Devin Mullins wrote:

Nikolai Weibull wrote:

> Devin Mullins wrote:

> > Making Wrong Code Look Wrong – Joel on Software

> That article is again proof that Joel is an utter idiot,
> nikolai (who’s thinking of registering joelisfud.com)

Well, I happen to think he's, like, 20% right on exceptions, and 5%
right on Hungarian, but again, while the particular solution is wacky,
the general solution is good, and well put: Make Wrong Code Look Wrong.

No?

Sure, but that has nothing to do with exceptions, and one can debate if
Hungarian notation is "the general solution". At that point, there’s
really not much left in his article to argue about. He wants to say
that we, as programmers, should make our intentions clear. Then he
suggests methods to achieve this goal that are totally whack and
expects every programmer in the world to accept it as gospel. I’m
sorry, but I really don’t like Joel.

About exceptions: Sure, they’re sort of like gotos, but the caller
decides where to go to, not the callee; big difference. Return-values
are like gotos as well, except they may or may not go to where they’re
supposed to. Hopefully the caller will have set up a destination, but
more often than not, it hasn’t.

http://tinyurl.com/ctcof and http://tinyurl.com/cb4v2 add further
insight,
        nikolai

···

--
Nikolai Weibull: now available free of charge at http://bitwi.se/\!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

Please consider the following code:

require 'net/http'
Net::HTTP.start('weather.gmdss.org') do |http|
  response = http.get('/III.html')
  response.body.scan(/<a.*a>/) {|link| puts "#{link}\n\n"}
end

I expect to have each html link printed separately but this is true only for the first three. The others are grouped together in two group.

This is what I get.

···

---------------------------------------
<a href="http://www.wmo.ch/index-fr.html" target="_blank"><img src="image/WMO.jpg" alt="WMO" border="0"></a>

<a href="http://www.meteo.fr" target="_blank"><img src="image/mf.gif" alt="MF" border="0"></a>

<a href="http://www.jcommweb.net/" target="_blank"><img src="image/jcomm90.jpg" alt="JCOMM" border="0"></a>

<a class="local" href="index.html">HOME PAGE</a><br><a class="local" href="I.html">METAREA I</a><br><a class="local" href="II.html">METAREA II</a><br><a class="local" href="III.html"><b>METAREA III</b></a>
[cut]

<a href="index.html">HOME PAGE</a> - <a href="III.html"><b>III</b></a></p> [cut]
-----------------------------------------

Any help will be really appreciated.

Bruno

response.body.scan(/<a.*?a>/)

(Note the question mark.)

Read up on greedy versus non-greedy matching in regular expressions.

Read up on greedy versus non-greedy matching in regular expressions.

Thanks !
No need to say that I'm a newbie. I'm coding with the pickaxe manual on my side and yes ... I miss the point: sorry.

But why did it work for the first three occurrences ?

Bruno

Because they're on their own line to begin with, and regular expressions (by default) work on a line-by-line basis.

You will probably also want to include the multiline option in your expression, otherwise you'll fail in situations like this as well:

<a href="foo.html">

un-necessary whitespace

</a>

matthew smillie.

···

On Dec 2, 2005, at 0:10, Bruno Bazzani wrote:

Read up on greedy versus non-greedy matching in regular expressions.

Thanks !
No need to say that I'm a newbie. I'm coding with the pickaxe manual on my side and yes ... I miss the point: sorry.

But why did it work for the first three occurrences ?