POV-Ray : Newsgroups : povray.off-topic : Context switching Server Time
4 Sep 2024 13:22:13 EDT (-0400)
  Context switching (Message 203 to 212 of 222)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Orchid XP v8
Subject: Re: Context switching
Date: 24 Apr 2010 06:02:46
Message: <4bd2c1c6$1@news.povray.org>
>> I would debate that, but let's not start another argument...
> 
>   Are you saying that you don't think one could write a significantly
> shorter command using perl than with your favorite language?

...alternatively, let's start another argument... *sigh*

> 
>     perl -pe 's|\d+|$&+1|ge' file.txt
> 
>   This searches for any consecutive digits in 'file.txt', interprets them
> as numbers and outputs the contents of the file but with each of these
> numbers incremented by 1. (Thus if the file had a something like
> "value = 123;" somewhere, the result would have "value = 124;" instead.)
> 
>   I don't know Haskell too well, but I'm pretty certain it takes a bit
> more code to do that

It does. (If only because of the difficulty of number parsing.) But a 
more relevant question would be... why would you want to do this? Is 
Haskell (or anything else) easier or harder for textual manipulations 
that actually do something useful?

> (and additionally you probably can't just write the
> code on the command line).

Actually you can. (But obviously you *only* want to do this if the code 
is short...)

>   Of course this is just a simple example. Perl can be used to make
> significantly more complex substitutions (and other things) in a similar
> way.

Again, I guess it depends on what you want to do. For example, some guy 
invented "markdown", and wrote a Perl script to turn it into HTML or 
whatever. And then a bunch of Haskell guys wrote their own 
implementation, which was faster, had fewer bugs (i.e., it matched the 
documentation more closely), and had more features.

Then again, not every task is as complicated as markup conversion...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Warp
Subject: Re: Context switching
Date: 24 Apr 2010 07:11:15
Message: <4bd2d1d3@news.povray.org>
Orchid XP v8 <voi### [at] devnull> wrote:
> why would you want to do this?

  Why would one want to do pattern substitution?

  Obviously nobody wants to do that, which is why there are no tools to do
that from, like, forever, like eg. 'sed' or 'perl'.

  I'm sure even you have used search&replace. This is the same, except that
it's significantly more expressive and can be automated.

-- 
                                                          - Warp


Post a reply to this message

From: Jim Henderson
Subject: Re: Context switching
Date: 24 Apr 2010 13:00:47
Message: <4bd323bf$1@news.povray.org>
On Sat, 24 Apr 2010 09:04:40 +0100, Orchid XP v8 wrote:

> Nicolas Alvarez wrote:
> 
>> Yesterday, the 'parted' tool was giving me a totally cryptic error
>> message.
>> 
>> $ apt-get source parted
>> $ cd parted-2.2
>> $ grep -rn "error message here" .
>> 
>> -r makes search recursive, -n makes grep output line numbers next to
>> the filenames. Then I opened a text editor on the file and line number
>> that grep mentioned, and tried to figure out the code :)
> 
> Isn't trying to figure out why an arbitrary piece of code doesn't work
> formally equivilent to the Halting Problem? (With non-termination simply
> being the most basic kind of program bug...)

You're not asking grep to tell you why it failed, just to tell you where 
in the code the error is so one can manually inspect the file and see if 
one can determine why the failure occurred.

Done that many times myself.

Jim


Post a reply to this message

From: Darren New
Subject: Re: Context switching
Date: 24 Apr 2010 13:52:56
Message: <4bd32ff8$1@news.povray.org>
Orchid XP v8 wrote:
> Isn't trying to figure out why an arbitrary piece of code doesn't work 
> formally equivilent to the Halting Problem? 

No.

The code works, in the formal sense. It just doesn't do what you want it to do.

-- 
Darren New, San Diego CA, USA (PST)
   Linux: Now bringing the quality and usability of
   open source desktop apps to your personal electronics.


Post a reply to this message

From: Darren New
Subject: Re: Context switching
Date: 24 Apr 2010 13:56:27
Message: <4bd330cb$1@news.povray.org>
Orchid XP v8 wrote:
> Such things are comparatively rare for Windows though. 

INI files is about it. Anything more complicated either goes in the registry 
or into an XML file, if it's configuration. Some log files actually go into 
text files, but that's mostly things like httpd logs there, too.

>> can be used (still usually with shorter commands and faster than writing
>> your own program would).
> 
> I would debate that, but let's not start another argument...

Using Perl *is* writing your own program. And I expect the parser generator 
in Haskell isn't a whole lot harder than an equivalet program in Perl.

-- 
Darren New, San Diego CA, USA (PST)
   Linux: Now bringing the quality and usability of
   open source desktop apps to your personal electronics.


Post a reply to this message

From: Darren New
Subject: Re: Context switching
Date: 24 Apr 2010 14:01:10
Message: <4bd331e6$1@news.povray.org>
Warp wrote:
>   Why would one want to do pattern substitution?

Personally, I usually wind up wanting to do complex pattern manipulation on 
file names, rather than file contents.

Stuff like "go through these directories full of image files, figure out 
whether it's months, days, or hours that's changing, rename all the files to 
match the time they were taking excluding the parts of the date that's the 
same for all the files, tack on a letter saying which camera took the 
picture, then another letter to disambiguate multiple photos taken within 
the same minute.   Also, copy any sequence of three or more photos taken 
within 5 seconds of each other with a one-minute gap on either side to a 
separate directory to be stitched together as a panorama."

That's gonna be rough to do with command-line tools too. Not impossible, but 
certainly something easier in an actual scripting language better than Bash.

-- 
Darren New, San Diego CA, USA (PST)
   Linux: Now bringing the quality and usability of
   open source desktop apps to your personal electronics.


Post a reply to this message

From: Darren New
Subject: Re: Context switching
Date: 24 Apr 2010 14:15:40
Message: <4bd3354c@news.povray.org>
Darren New wrote:
> Orchid XP v8 wrote:
>> Isn't trying to figure out why an arbitrary piece of code doesn't work 
>> formally equivilent to the Halting Problem? 
> 
> No.
> 
> The code works, in the formal sense. It just doesn't do what you want it 
> to do.

Or, to clarify...

If by "works" you mean "obeys the formal specification", then yes, you can 
prove it.  Write a formal spec for what sequence a Haskell program can 
output, such as a BNF grammar. Now analyze your Haskell program to see if 
the parser you wrote follows the BNF.

Computers do this all the time. There's an input language the compiler 
accepts. It can tell whether the input matches the language spec, and if so, 
the program "works", in some sense.

And indeed, this is called the field of "program verification", pioneered by 
those who invented structured programming and such.

-- 
Darren New, San Diego CA, USA (PST)
   Linux: Now bringing the quality and usability of
   open source desktop apps to your personal electronics.


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Context switching
Date: 24 Apr 2010 14:20:33
Message: <4bd33671@news.povray.org>
Orchid XP v8 wrote:
> Nicolas Alvarez wrote:
>> Invisible wrote:
>>> 3. It really takes that much code just to do the same task as DIR /B C:\
>>>  C:\FileList.txt?
>> 
>> Says the guy who would rather write his own program to do specific
>> searches than figure out grep :)
> 
> Or rather, I'd rather write my own program than use grep for a *complex*
> search. (E.g., find anything that's a valid XML fragment.)
> 

Well, sure. Regular expressions are almost always the wrong tool for XML.


Post a reply to this message

From: Orchid XP v8
Subject: Re: Context switching
Date: 24 Apr 2010 14:27:35
Message: <4bd33817$1@news.povray.org>
>> Isn't trying to figure out why an arbitrary piece of code doesn't work
>> formally equivilent to the Halting Problem? (With non-termination simply
>> being the most basic kind of program bug...)
> 
> You're not asking grep to tell you why it failed, just to tell you where 
> in the code the error is so one can manually inspect the file and see if 
> one can determine why the failure occurred.

Oh, sure. I just meant that even once grep has found the location for 
you, the task you're attempting to perform is almost impossible anyway...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Orchid XP v8
Subject: Re: Context switching
Date: 24 Apr 2010 14:30:49
Message: <4bd338d9$1@news.povray.org>
Warp wrote:
> Orchid XP v8 <voi### [at] devnull> wrote:
>> why would you want to do this?
> 
>   Why would one want to do pattern substitution?

No, why would you want to find anything that's a number, parse it, and 
add one to it. It doesn't seem like a particularly useful example. I'm 
sure the same techniques could be used to do something more useful, but 
I can't think of an example.

Anyway, I forget how we even got started on this topic, but this debate 
has gone on long enough to make a few things clear. It seems that 
low-level text munging is useful for the kind of stuff you do, and not 
especially useful for the kind of stuff I do. Let's leave it at that.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.