Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Hints Towards Writing a Module with New Operators

by JadeNB (Chaplain)
on Dec 20, 2009 at 00:37 UTC ( #813570=note: print w/replies, xml ) Need Help??


in reply to Hints Towards Writing a Module with New Operators

The little Fortran documentation that I can find by Googling suggests that, as moritz (implicitly) points out, .EQV. is just == on Booleans. If this is correct, are you just looking to bring to Perl the syntactic beauty of Fortran :-)—or is it that you want something that does the Boolean conversion for you, so that you can write $a .EQV. $b ** as the equivalent of $a ? $b ? 1 : 0 : $b ? 0 : 1 *?

Either way, as moritz says, for adding new syntax to Perl-as-it-now-is, I think that the only options are syntax filters (struck out as I write it so that you don't even think about it) or Devel::Declare (which worries adamk).

* Or ($a && $b) || !($a || $b), I suppose. UPDATE: Ha, and maybe I'd like to write my own routines for addition while I'm at it. Thanks, JavaFan. :-)

UPDATE: ** Note that this precise syntax conflicts with string concatenation, but we shouldn't be using barewords anyway.

Replies are listed 'Best First'.
Re^2: Hints Towards Writing a Module with New Operators
by JavaFan (Canon) on Dec 20, 2009 at 01:00 UTC

      Or

      1. .NEQV. ~= $a ^ $b
      2. .EQV. ~= !($a ^ $b)

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Those aren't the same:
        !(2 xor 1); # => 1 !(2 ^ 1); # => 0
Re^2: Hints Towards Writing a Module with New Operators
by ikegami (Pope) on Dec 20, 2009 at 08:48 UTC

    You could also use

    !$a == !$b

    but that relies on the fact than the true and false values returned by Perl ops are 1) always the same, and 2) numeric*. xor is definitely the way to go.

    * — They're also strings, but that's not relevant here.

Re^2: Hints Towards Writing a Module with New Operators
by swampyankee (Parson) on Dec 20, 2009 at 23:14 UTC

    Considering .EQV. as == for booleans is more or less correct: a .eqv. b is true if a and b are either both true or both false, and it would result in false otherwise. Most modern Fortran compilers will squawk if either a or b isn't a boolean (Fortran logical), so a fragment like

    logical boole integer int int = 42 boole = .TRUE. write(*,*) 'is int .eqv. boole true?', int .eqv. boole
    will cause a compile-time error, which is, on the whole, probably a good thing. As I said in my original post, I've been programming Fortran for quite a few years and never found a use for .eqv. or .neqv.. As an aside, Fortran is insensitive to case; I tend to use uppercase for Fortran keywords and lowercase for everything else.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://813570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-08-16 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (167 votes). Check out past polls.

    Notices?