Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

perl- a game of rock-paper-scissors

Name: Anonymous 2009-10-18 1:30

i am teaching myself perl. i want to have two scrips play r-p-s and a third to keep score. for now it will be on a single computer. then over a network. im using linux.

Name: Anonymous 2009-10-18 1:37

sorry i forgot my problem.

how to i make the third script poll the  playing scrips. i dont want them to write to an external file over and over. i want the variables to be stored within the program and be dynamically read by the third.

sorry to ramble i just dont know where to start.

Name: Anonymous 2009-10-18 1:43

i want the variables to be stored within the program and be dynamically read by the third.
No you don't. Use pipes or something.

Name: Anonymous 2009-10-18 1:48

That's a horrible way.  You probably want a host and a client, and just have the client and host send the RPS to eachother, and have the program keep it a secret until the host realises that both have been sent, then it tells the client to show what each player picked and who won.  The host will keep track of all the data and just send it to the client.

Unless you really want to have a dedicated host that two clients connect to, but it still would be the same principle.

Name: Anonymous 2009-10-18 3:17

>>4
horrible D:

o well. thanks for the help. that will give me a start.

Name: Anonymous 2009-10-18 3:47

acchi muite hoi!

Name: Anonymous 2009-10-18 5:44


Id recommend using something else than perl though. The only sensible reason to learn perl these days are to maintain old perl code. You don't write new stuff in perl anymore.

Name: Anonymous 2009-10-18 5:46

>>7
bah humbug.
perl is the modern equivalent to shell scripts

Name: Anonymous 2009-10-18 5:53

>>8
Shell scripts are the modern equivalent to shell scripts.

Name: Anonymous 2009-10-18 5:56



perl is good if you like to produce unmaintainable garbage!

Name: Anonymous 2009-10-18 5:58

ITT: Lisptards who are butthurt about how Perl is so much better than their language.

Name: Anonymous 2009-10-18 6:13

>>11
I don't think anybody mentioned Lisp in this thread. Shows how unsecure you are about your choice of language.

Name: Anonymous 2009-10-18 6:24

>>11
as both a perl and lisp lover i came to the conclusion that you are gay and like to fail .

please stop fagging up my /prog/ ,

also i love garbage .

Name: Anonymous 2009-10-18 6:32

>>12,13
YHBT

Name: Anonymous 2009-10-18 6:33


quote: "also I love garbage"

Sure, I bet you do...

Name: Anonymous 2009-10-18 7:30

OP here.

>>13
i love garbage too.

>>11
i am also wanting to learn lisp.

-----------
now i just craped up my thread. :P

Name: Anonymous 2009-10-18 7:57

(defun r-p-s ()            
  (elt '(r p s) (random 3)))
(defun win (x y)             
  (subsetp (member x '(r p s))
           (member y '(r p s))))
(defun run (&optional (times 0))
  (loop until (zerop (decf times))
       collect (win (r-p-s) (r-p-s))))

Name: Anonymous 2009-10-18 8:05

>>17
hello please explain &rest and &body to me thanks

Name: not->>17 2009-10-18 8:19

>>18
&rest just means that the rest of the arguments that are passed to the function after that parameter are consed up into a list. The rule is similar to that for macros, but it's a bit more generic in that it allows arbitrary destructuring
http://www.lispworks.com/documentation/HyperSpec/Body/03_dac.htm
&body is exactly like rest, but is usually only seen in macros, the only difference is that it can be used to inform the implementation's pretty printer and (maybe) the editor of correct indentation to be used (usually 2 spaces) for body forms (usually a macro would place them in an implicit PROGN.

Name: >>19 2009-10-18 8:21

Here's a simple example showing how to use &rest to implement FUNCALL using APPLY.

(defun funcall (function &rest arguments)
  (apply function arguments))

Name: Anonymous 2009-10-18 8:55

>>19
So, it's used for functions of variable arity?

Name: Anonymous 2009-10-18 9:12

>>21
Yes, but its usage can be generalized for destructuring lambda lists (used in macros or destructuring-bind), where you can use it arbitrarily within nested lists, to illustrate what I mean, here's an example:


(destructuring-bind (a (b (c d &rest args) (&key e) &optional (f 'something)))
    '(123 (456 (789 1 sym1 sym2 :whatever) (:e 123)))
  `(,a ,b ,c ,d ,@args ,e ,f))
;=> (123 456 789 1 SYM1 SYM2 :WHATEVER 123 SOMETHING)

(destructuring-bind (a (b (c d &rest args) (&key e) &optional (f 'something)))
    '(123 (456 (789 1 sym1 sym2 :whatever) (:e 123)))
  (list a b c d args e f))
;=>(123 456 789 1 (SYM1 SYM2 :WHATEVER) 123 SOMETHING)

Name: Anonymous 2009-10-18 10:17

>>19
&body is exactly like rest, but is usually only seen in macros
In fact, I tried using &body in a defun in SBCL once, and it didn't work. It only allows &rest.

Name: Anonymous 2009-10-18 10:28

The thing is, gentlemen, if you will, that new code is in fact written in Perl, whereas no code for anything that goes into production is ever written in Lisp.

As a demonstration let's Google for jobs in both languages:

perl jobs
3070000 results

lisp jobs
92700 results

QED: gentlemen, your precious mickey mouse language is irrelevant in the real world of employable skills.

Also: only if you've caught the gay do you have a lisp

Name: Anonymous 2009-10-18 10:29

>>23
Of course it wouldn't work, the standard says that defun just supports ordinary lambda lists, which does not include &body. It's usually meant to signal a body of code (for example what you put after the argument list in a defun, this body is also usually enclosed in a PROGN within the macro code (progn ,@body). Functionaly it's the same as &rest, however when you're dealing with something meant to process code(such as a macro), &body can be used to simply let the user know that this is the code that would be inserted into the macroexpansion, it also can be used by the pretty-printer and editor as a hint on how to indent it.)

For more information about specific differences between lambda lists see:

http://www.lispworks.com/documentation/HyperSpec/Body/03_d.htm

Name: Anonymous 2009-10-18 10:32

>>24
What makes you think people learn Lisp for a job?
They learn it to expand their knowledge, programming techniques and to have a great tool that they can use for themselves. If you're learning Lisp to get a specific job, you're either stupid, or someone wants you to maintain the codebase of some fleeting Lisp wizard.

As for you >>24, get back to work, your boss is calling you!

Name: Anonymous 2009-10-18 10:39

To continue from the above:

Where I work we employ Ruby devs and just hired two new ones. The job requirements did not specify Ruby experience, just a desire to learn. However experience in Perl,C, or C++ *was* required. Lisp usage never a consideration.

Many people experiment during their University career; some with drugs and/or sexuality, others with Lisp or Haskell. You will outgrow your childish indiscretions when you start needing to pay the bills.

Name: Anonymous 2009-10-18 10:46



Perl is deprecated. Should and will be replaced with Python.

Name: Anonymous 2009-10-18 10:48

>>28
Go away Guido.

Name: Anonymous 2009-10-18 10:50

>>28
har har har har har har

Name: Anonymous 2009-10-18 10:51

>>28
One word: installed user base.

Name: Anonymous 2009-10-18 13:14

>>17
Rock beats rock, paper beats rock, scissors beat rock.  Brilliant!

>>28
Perl > Python.

Name: Anonymous 2009-10-18 17:06



Where I work you aren't even allowed to write Perl code. Bash, Python, Ruby, C, C++, Ocaml, Fortran  and so on are all ok.

Brainfuck is probably not ok, for the same reasons.

Name: Anonymous 2009-10-18 17:12

>>33
HASKAL?

Name: UMH memesmith !gNlkr4vCuc 2009-10-18 17:19

>>34
No :|

Name: Anonymous 2009-10-18 17:42

>>33
Where you work is dumb.

Name: Anonymous 2009-10-18 22:50

>>33
That's what happens when you get a job working the register at Walmart, which incidentally is the only job your University Lisp and Haskell programming experience qualifies you for.

Name: Anonymous 2009-10-18 23:50

>>33
The only people that can't read Perl are people who can't write Perl.
I have no problems reading and understanding it.

Name: Anonymous 2011-02-03 7:45

Don't change these.
Name: Email:
Entire Thread Thread List