Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Re: Coding: Fleeting Thoughts

Postby Dropzone » Wed Nov 26, 2008 11:22 pm UTC

Well, this is certainly the gnarliest piece of Java coding I've ever done, and it's making for some interesting error messages as I try to get it to work.

Exhibit 1:
jwalkerror1.png
jwalkerror1.png (6.55 KiB) Viewed 2934 times

Exhibit 2:
Spoiler:
jwalkerror2.png
Yes, the message box is too big to fit on the screen. Check out that call stack...
jwalkerror2.png (212.76 KiB) Viewed 2899 times
User avatar
Dropzone
 
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Coding: Fleeting Thoughts

Postby Rysto » Wed Nov 26, 2008 11:50 pm UTC

On the first error, my two guesses are:

a) The error message is wrong
b) You're messing with classloader stuff, and have two distinct instances of that class loaded.
Rysto
 
Posts: 1420
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Nov 27, 2008 1:13 am UTC

Dropzone wrote:Well, this is certainly the gnarliest piece of Java coding I've ever done, and it's making for some interesting error messages as I try to get it to work.

Exhibit 1:
jwalkerror1.png



I'm thinking it's a cast from org.jwalk.JWalk to org.jwalk.JWalk.subclass, but it doesn't fit in the dialog.
Blag.
Ternary computer emulator. Latest version is 0.5 [Nov 29 2008].

Good morning, that's a nice tnetennba.
User avatar
You, sir, name?
 
Posts: 6128
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Coding: Fleeting Thoughts

Postby Dropzone » Thu Nov 27, 2008 5:59 pm UTC

Nope, Rysto's second guess was right - I had the same class loaded twice through two different classloaders, and was effectively trying to cast from one classloader's copy of the class to the other classloader's (which isn't allowed).
User avatar
Dropzone
 
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Coding: Fleeting Thoughts

Postby Berengal » Fri Nov 28, 2008 2:52 pm UTC

Oh ruby, you are so wacky fun. I finally decided to learn it properly yesterday, and I'm enjoying it immensely. I wonder what Dijkstra would say about "redo" and "retry", but I like them (as a concept, at least. Not too sure about their use in practical code, especially in regards to readability).

Project Euler problem 4 solution:
Code: Select all
def p4
  (100..1000).to_a.combination(2).select do |a,b|
    c = (a * b).to_s
    c == c.reverse
  end.max_by do |a|
    a.reduce do |a,b| a * b end
  end
end

I only realized just now that I'm using three different variables name "a"; the first of two numbers given by combination(2), the array of two numbers given by max_by, and the first of those two numbers in reduce... Oh well, wacky fun indeed.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Coding: Fleeting Thoughts

Postby Guff » Sat Nov 29, 2008 12:27 am UTC

So I just got my extremely crude and messy Hangman/Wheel of Fortune-guesser written in Python working. Mostly.
First, it takes the puzzle as input (blanks represented by underscores), and breaks it up into a list of words. Then, a string of all letters not already used and not already called is substituted for each underscore (and put between brackets, so we get something like '[abcd]'), which can then be turned into regexes. Then it searches the *nix words and propernames files and makes a list of all matches. Then it determines which are the most likely to be correct based on the number of search results returned by Google.

Problems with this:
  • It looks like it was coded by someone who either sucks at Python or didn't realize he was writing in Python. Though, I maintain that's a feature, not a bug.
  • The Google-as-an-oracle thing might suffice if you're tracking a flu outbreak, but as I learned upon my initial test, it can be very misleading. Said test involved feeding the script 'h_llo'. What it returned was 'hallo'. I thought "that can't be right," so I manually checked Google. And of course, 'hallo' returns roughly three times the amount of results that 'hello' does.
  • Finding the amount of results for each candidate word is very faulty. So, what might work better is testing pairs of words, but that's harder to implement and I'm kind of sleepy and have a paper to write (that I should have written about two weeks ago). A second issue is that of combinatorial explosion; querying Google (especially when doing it through a hackish use of urllib instead of the actual Google API) isn't very quick, and the program already suffers from speed issues.

So, I've got to find a smarter way of determining the likelihood of candidate words being correct. Sticking somewhat closely to my initial idea, I'm not sure how this could be done short of the pairing, and I'm not quite sure how to best implement that. Oh well, I'll get to it later.
User avatar
Guff
 
Posts: 165
Joined: Thu Jan 03, 2008 11:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby MoD » Sat Nov 29, 2008 3:12 am UTC

Can it solve "S-H-_-_-K _-_-_-_-C-K"? :P
Last edited by MoD on Thu Jan 22, 2009 12:48 pm UTC, edited 1 time in total.
User avatar
MoD
 
Posts: 107
Joined: Sun Dec 30, 2007 4:55 pm UTC

Re: Coding: Fleeting Thoughts

Postby Guff » Sat Nov 29, 2008 3:50 am UTC

MoD wrote:Can it solve "S-H-_-_-K _-_-_-_-C-K"? :P

Well, a simple manual Google search did (as it's from a song, apparently). My script might have problems, given the lack of letters (both used and unused).

I had to work out a couple of bugs in the program before I could try this, and apparently there's at least one more bug in it. It gave me "shook goback". To be fair on the script, though, 'goback' does give more results than 'attack'. Problem: 'shark' gives more results than 'shook'. Either I made an error, or the program has become self-aware and figured out that 'shook goback' actually gives more results than 'shark attack'.

Marvel at my skill. :D

Edit: amazingly, feeding it 'o' as an unused letter led to the correct answer.
User avatar
Guff
 
Posts: 165
Joined: Thu Jan 03, 2008 11:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby 3fj » Thu Dec 04, 2008 9:29 am UTC

why use a typedef to define boolean!?

Isn't that just a little anal?
Fa la la! It's off to hell we go!
User avatar
3fj
 
Posts: 1629
Joined: Wed Jun 11, 2008 1:13 pm UTC
Location: Land of Whisky and Bagpipes (LOWAB)

Re: Coding: Fleeting Thoughts

Postby Posi » Fri Dec 05, 2008 4:14 am UTC

So I found a partial solution to my VHDL problems hell: ghdl. I code the task in Kate (which happens to be a much better text editor than the one the class requires (it adds infinite spaces to the end of each line, which is horribly annoying when trying to use the arrow keys to move arround)), then compile it with ghdl. It provides actually useful error messages, and I have found that after about two days of usage, I get way less syntax errors.

When I get it working there, I copypasta it to the crappy school program and get syntax errors. I've found these are mostly unsupported features, an come up with a hacky workaround.

Also, for a class I am taking next semester, I am required to know a high level programming language such a C.
Posi
 
Posts: 111
Joined: Mon Jul 16, 2007 6:08 am UTC

Re: Coding: Fleeting Thoughts

Postby Ephphatha » Sat Dec 06, 2008 8:18 am UTC

Still working on this connect four game. I'm about ready to start sending data from the client to the server. The problem I have now is getting it to work well in a message based environment. I need to get the host to start accept()ing connections when they are requested, and then start recieving data. I figure I can create a timer when I call listen() and get that timer to call a function (or post a message) that checks if there are any connections to accept(). If there is I spawn another timer for each connection and get that timer to call a function or post a message recv()ing data.

This just seems a bit wasteful. If I have 3 clients, that's four timers running, three doing pretty much the same thing. I'm going to be storing the client sockets in an array, so maybe I can just use two timers. One to check if there are connections waiting to be accept()ed, and the other iterates through each client socket checking if there is data to be recv()ed.

Ideas? (This is the first time I've tried to implement network support for any application I've written, so I could well be complicating things.)
I'm not lazy, I'm just getting in early for Christmas is all...
User avatar
Ephphatha
 
Posts: 625
Joined: Sat Sep 02, 2006 9:03 am UTC
Location: Bathurst, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby wing » Sat Dec 06, 2008 10:49 am UTC

FUCK SMTP SERVERS.

Seriously.

The one for my client sits behind a firewall, so I can't access it remotely (double-WTF: Cisco VPN client doesn't support 64bit OSes, so I can't hop the firewall. triple-WTF: They set up a workaround on the VPN concentrators for the wireless networks that allows 64-bit users to use Vista's inbuilt VPN function - but they didn't do that on the concentrator for external connections).
The one for my ISP steadfastly refuses any attempt to use it programatically - lord knows why regular email clients work.
My ISP filters me from using any third-party SMTP servers - thanks, fuckhats. I pay for a business account and you still treat me like a consumer that needs to have his nuts caressed gently at all times.

This means I need to go on-site to program and test the mail module. GRR.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Rysto » Sat Dec 06, 2008 6:09 pm UTC

Ephphatha, I believe that select( ) is what you're looking for.
Rysto
 
Posts: 1420
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Coding: Fleeting Thoughts

Postby '; DROP DATABASE;-- » Sun Dec 07, 2008 3:58 am UTC

Code: Select all
****************************************************************************
** COP1 - Floating Point Unit (FPU)                                       **
****************************************************************************

    COP1: Instructions encoded by the fmt field when opcode = COP1.
    31--------26-25------21 ----------------------------------------0
    |  = COP1   |   fmt   |                                         |
    ------6----------5-----------------------------------------------
    |--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
 00 | MFC1  | DMFC1 | CFC1  |  ---  | MTC1  | DMTC1 | CTC1  |  ---  |
 01 | *1    |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
 10 | *2    | *3    |  ---  |  ---  | *4    | *5    |  ---  |  ---  |
 11 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
 hi |-------|-------|-------|-------|-------|-------|-------|-------|
     *1 = BC instructions, see BC1 list
     *2 = S instr, see FPU list            *3 = D instr, see FPU list
     *4 = W instr, see FPU list            *5 = L instr, see FPU list

    BC1: Instructions encoded by the nd and tf fields when opcode
         = COP1 and fmt = BC
    31--------26-25------21 ---17--16-------------------------------0
    |  = COP1   |  = BC   |    |nd|tf|                              |
    ------6----------5-----------1--1--------------------------------
    |---0---|---1---| tf
  0 | BC1F  | BC1T  |
  1 | BC1FL | BC1TL |
 nd |-------|-------|

    FPU: Instructions encoded by the function field when opcode = COP1
         and fmt = S
    31--------26-25------21 -------------------------------5--------0
    |  = COP1   |  = S    |                               | function|
    ------6----------5-----------------------------------------6-----
    |--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
000 | ADD   | SUB   | MUL   | DIV   | SQRT  | ABS   | MOV   | NEG   |
001 |ROUND.L|TRUNC.L| CEIL.L|FLOOR.L|ROUND.W|TRUNC.W| CEIL.W|FLOOR.W|
010 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
011 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
100 |  ---  | CVT.D |  ---  |  ---  | CVT.W | CVT.L |  ---  |  ---  |
101 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
110 | C.F   | C.UN  | C.EQ  | C.UEQ | C.OLT | C.ULT | C.OLE | C.ULE |
111 | C.SF  | C.NGLE| C.SEQ | C.NGL | C.LT  | C.NGE | C.LE  | C.NGT |
 hi |-------|-------|-------|-------|-------|-------|-------|-------|

    FPU: Instructions encoded by the function field when opcode = COP1
         and fmt = D
    31--------26-25------21 -------------------------------5--------0
    |  = COP1   |  = D    |                               | function|
    ------6----------5-----------------------------------------6-----
    |--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
000 | ADD   | SUB   | MUL   | DIV   | SQRT  | ABS   | MOV   | NEG   |
001 |ROUND.L|TRUNC.L| CEIL.L|FLOOR.L|ROUND.W|TRUNC.W| CEIL.W|FLOOR.W|
010 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
011 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
100 | CVT.S |  ---  |  ---  |  ---  | CVT.W | CVT.L |  ---  |  ---  |
101 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
110 | C.F   | C.UN  | C.EQ  | C.UEQ | C.OLT | C.ULT | C.OLE | C.ULE |
111 | C.SF  | C.NGLE| C.SEQ | C.NGL | C.LT  | C.NGE | C.LE  | C.NGT |
 hi |-------|-------|-------|-------|-------|-------|-------|-------|

    FPU: Instructions encoded by the function field when opcode = COP1
         and fmt = W
    31--------26-25------21 -------------------------------5--------0
    |  = COP1   |  = W    |                               | function|
    ------6----------5-----------------------------------------6-----
    |--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
000 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
001 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
010 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
011 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
100 | CVT.S | CVT.D |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
101 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
110 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
111 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
 hi |-------|-------|-------|-------|-------|-------|-------|-------|

    FPU: Instructions encoded by the function field when opcode = COP1
         and fmt = L
    31--------26-25------21 -------------------------------5--------0
    |  = COP1   |  = L    |                               | function|
    ------6----------5-----------------------------------------6-----
    |--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
000 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
001 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
010 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
011 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
100 | CVT.S | CVT.D |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
101 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
110 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
111 |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
 hi |-------|-------|-------|-------|-------|-------|-------|-------|
AGH WHO DESIGNED THIS

wing, I agree with your sentiment.

And Firefox, stop fucking doubling my line breaks >8^(
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.
User avatar
'; DROP DATABASE;--
 
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy

Re: Coding: Fleeting Thoughts

Postby Ephphatha » Sun Dec 07, 2008 6:51 am UTC

Rysto wrote:Ephphatha, I believe that select( ) is what you're looking for.

Well, the sockets are all set to not block so wasteful calls to recv() just trigger error 10035.
I'm not lazy, I'm just getting in early for Christmas is all...
User avatar
Ephphatha
 
Posts: 625
Joined: Sat Sep 02, 2006 9:03 am UTC
Location: Bathurst, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby wing » Sun Dec 07, 2008 8:13 am UTC

Just in case anyone's wondering, I resolved my SMTP issues by putting in a call to my ISP's security department (with their direct number, which I got by ferreting out their headquarters number block, dialing the first number in the block (which turned out to be their AUDIX directory), and going through the list until it gave me the direct line to Network Security) who informed me of an unpublished SMTP server they run for programmatic usage - and informed me that the server logs everything and that someone DOES watch it for spam and will come kill me if I abuse it.

It works great.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Dropzone » Tue Dec 16, 2008 8:03 pm UTC

The Java Language Specification, Third Edition, section 15.26.2:

A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

Some Java code:

Code: Select all
Object e1 = "foo";
String e2 = "bar";

e1 += e2;                   // compile error
e1 = (Object)((e1) + (e2)); // works fine

What...
User avatar
Dropzone
 
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Dec 17, 2008 3:02 am UTC

Dropzone wrote:
Code: Select all
Object e1 = "foo";
String e2 = "bar";

e1 += e2;                   // compile error
e1 = (Object)((e1) + (e2)); // works fine

What...
I don't think "Object" implements the addition operator. The second one may (for some reason...) interpret the first operator's ToString(), since it knows at least one of them is a string. But in the first, it works based on the type of the first operator, which is an Object (and doesn't have addition).

I'd like to see the output string from the second one, just to be sure that's what happened, but that's my best guess. It will probably end up as a pointer followed by bar though, rather than foobar.
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4409
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby Qoppa » Wed Dec 17, 2008 3:18 am UTC

Haskell is fucking with my brain.

Ow.

I thought my knowledge of Scheme would help, but apparently it doesn't. Still, Haskell is awesome. Quite different from what I was expecting, but that just makes it even cooler. I can't wait until I can actually use it.
Code: Select all
_=0,w=-1,(*t)(int,int);a()??<char*p="[gd\
~/d~/\\b\x7F\177l*~/~djal{x}h!\005h";(++w
<033)?(putchar((*t)(w??(p:>,w?_:0XD)),a()
):0;%>O(x,l)??<_='['/7;{return!(x%(_-11))
?x??'l:x^(1+ ++l);}??>main(){t=&O;w=a();}
User avatar
Qoppa
 
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Why Two Kay » Wed Dec 17, 2008 3:28 am UTC

Addition is apparently no longer commutative when working with limited precision integers.

On my AP Comp Sci 2 test today I had to rewrite the following expression, or one close to it, in post-fix notation.

(A+B+C) - D * E - F/G

I started off:
ABC++ and you see where it goes from there.

Java Integer is bounded on -2147483648 and 2147483647

In the event that C was 2147483646, B was 3 and A was -5, the results of

(A+B) + C

and

(C+B) + A

would result in different things. Adding A and B together first results with -2, and adding that to 2147483646 is quite fine.

But adding 3 to 2147483646 is not fine, so adding C to B first results in an overflow exception and a very messed up result.

Oh well.
tl;dr - I said nothing important.
User avatar
Why Two Kay
 
Posts: 266
Joined: Sun Mar 23, 2008 6:25 pm UTC
Location: Plano, TX

Re: Coding: Fleeting Thoughts

Postby Berengal » Wed Dec 17, 2008 3:33 am UTC

No, toString() (like most java methods) is virtual, so it produces "foobar".

And yes, it seems java knows to call the toString() method as long as at least one of it's operands is a String. At least that's what preliminary testing suggests. It's a little strange, the error you get with e1 += e2 though:
Code: Select all
Main.java:7: incompatible types
found   : java.lang.Object
required: java.lang.String
    e1 += e2;
    ^
1 error


I think the specification meant primitive types only, in which case it's not... uh, specific enough.


Why Two Kay wrote:In the event that C was 2147483646, B was 3 and A was -5, the results of

(A+B) + C

and

(C+B) + A

would result in different things.


No:
Code: Select all
int a, b, c;
    a = -5;
    b = 3;
    c = 2147483646;

    System.out.println((a + b) + c);
    System.out.println((c + b) + a);


[berengal@Sjur ~/dev/java]$ java Main
2147483644
2147483644


Twos compliment integer addition and subtraction doesn't care about sign bits, and is simple modulo 2^32 arithmetic. As long as it underflows as many times as it overflows, and you're not doing multiplication or division (those care about signs), you should be fine. I've never heard of an overflow exception before...
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Coding: Fleeting Thoughts

Postby sparkyb » Wed Dec 17, 2008 4:27 am UTC

Why Two Kay wrote:On my AP Comp Sci 2 test today I had to rewrite the following expression, or one close to it, in post-fix notation.

(A+B+C) - D * E - F/G


So then the answer, using the same order of operation/precedence would be: AB+C+DE*-FG/- ?
User avatar
sparkyb
 
Posts: 956
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville unincorperated territories

Re: Coding: Fleeting Thoughts

Postby Why Two Kay » Wed Dec 17, 2008 5:28 am UTC

sparkyb wrote:
Why Two Kay wrote:On my AP Comp Sci 2 test today I had to rewrite the following expression, or one close to it, in post-fix notation.

(A+B+C) - D * E - F/G


So then the answer, using the same order of operation/precedence would be: AB+C+DE*-FG/- ?


That looks right, I think I would have put.

CBA++DE*-FG/-

And that point about it working fine is interesting... I might bring that up if I missed anything else on the test.
tl;dr - I said nothing important.
User avatar
Why Two Kay
 
Posts: 266
Joined: Sun Mar 23, 2008 6:25 pm UTC
Location: Plano, TX

Re: Coding: Fleeting Thoughts

Postby wing » Wed Dec 17, 2008 8:49 pm UTC

I dislike .net Threads. It just seems... Hackish compared to Java's implementation.

Also, MWAHAHAHA, I'VE PROGRAMMED A SATELLITE CLOCK. BILLIONS OF DOLLARS OF TECHNOLOGY AND ATOMIC CLOCKS THROWN UP IN ORBIT, EQUATIONS INVOLVING FUCKING RELATIVITY, AND I'M USING IT AS A CLOCK.

... Those little rushes of power when you complete your excessively simple initial test for implementation of a vast, complicated system are awesome, aren't they?

I've reduced the entire GPS constellation to a desktop clock for this one.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Qoppa » Wed Dec 17, 2008 10:58 pm UTC

Haskell gurus!

Help a n00b out. For my first program (yay!), I'm trying to make a function which takes n as a parameter, and generates the first n Fibonacci numbers as a list. But of course it's not working. Haskell is confusing.

Code: Select all
fiblist :: Int -> [Integer]
fiblist 0 = []
fiblist 1 = [0]
fiblist 2 = [0, 1]
fiblist n = prev : (prev !! (n - 1) + prev !! (n - 2))
        where
        prev = fiblist (n - 1)

I know this is almost certainly not the best way to go about this, so don't bother pointing out how you can do it much more succinctly. The error I'm getting is 'Couldn't match expected type 'Integer' to inferred type '[Integer]', and it's referring to the first place where we see 'prev'.

EDIT: Hahahahaha, Berengal's signature is exactly what I'm talking about. One line, and then there's my bloated code. Still, it'd be cool to get what I wrote working.
Code: Select all
_=0,w=-1,(*t)(int,int);a()??<char*p="[gd\
~/d~/\\b\x7F\177l*~/~djal{x}h!\005h";(++w
<033)?(putchar((*t)(w??(p:>,w?_:0XD)),a()
):0;%>O(x,l)??<_='['/7;{return!(x%(_-11))
?x??'l:x^(1+ ++l);}??>main(){t=&O;w=a();}
User avatar
Qoppa
 
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Berengal » Thu Dec 18, 2008 1:11 am UTC

(prev !! (n-1) + prev !! (n -2)) is an Integer. You're trying to cons a list to that. That doesn't work. (:) :: a -> [a] -> [a], not [a] -> a -> [a].

You could switch the statements around, but that'd yield the list in reverse. To do this your way, you're going to need a helper function working it's way backwards over the list, something like
Code: Select all
-- fiblist 0|1|2 already defined
fiblist n = 0:1:fiblist' n 0 0 1
  where fiblist' n c a b | n < c     -> []
                         | otherwise -> (a + b):fiblist' n (c+1) b (a+b)
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Coding: Fleeting Thoughts

Postby Qoppa » Thu Dec 18, 2008 5:34 am UTC

Ahh, I see. Thanks! I switched the order around, and then just reversed the list in another function. Terrible way to go about doing it, but hey, I've actually written something in Haskell now!
Code: Select all
_=0,w=-1,(*t)(int,int);a()??<char*p="[gd\
~/d~/\\b\x7F\177l*~/~djal{x}h!\005h";(++w
<033)?(putchar((*t)(w??(p:>,w?_:0XD)),a()
):0;%>O(x,l)??<_='['/7;{return!(x%(_-11))
?x??'l:x^(1+ ++l);}??>main(){t=&O;w=a();}
User avatar
Qoppa
 
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Berengal » Thu Dec 18, 2008 6:28 am UTC

Working with linked lists can be a minor mindbender at first, but it should come naturally quick enough. I like to think about listbuilders as making paperclip chains using a paperclip dispenser that dispenses the paperclips in a certain order. You could start with the empty paperclip chain and cons the first paperclip onto that, then recurse with the smaller dispenser and the now one-element chain, but that leaves you holding the last paperclip when you're done. You could also take the first paperclip, give the dispenser to a clone of yourself and ask him to build a list out of it, and then cons your paperclip onto the chain he gives you back, leaving you holding the first paperclip and preserving the order the dispenser dispensed the paperclips in. This last way is the only way you can preserve order in infinite lists, because they're a bit hard to reverse.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Coding: Fleeting Thoughts

Postby Guff » Thu Dec 18, 2008 9:52 pm UTC

Oh god, why did I get into J?

It's such a strange, total mindfuck of a language. Though, that would seem to run in the family, what with APL and all.
Nevertheless, I kind of like it. Never dealt with any language quite like it before, and my experience so far with it consists of trying to learn it at 3 in the morning earlier today, so I still don't quite have the hang of it.
Calculating the nth triangular number, for example (as a sum, rather than a polynomial [yeah sure the polynomial's simpler and has a larger domain but it's not as great for demonstration]): tri=:+/&i.&>:

Yeah, I think I'll stick to Python as my primary language. But this is still pretty fun.
User avatar
Guff
 
Posts: 165
Joined: Thu Jan 03, 2008 11:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby Rekreativc » Fri Dec 19, 2008 10:39 am UTC

wow, this is really bothering me atm ... I can't find a way to "discover" if a scroll bar is present in list view ( C# )... What really bothers me is that Form class has a bool property indicating the presence of either, vertical or horizontal scroll bar, and list view doesn't have one ... sux

anyway, if someone has any idea about this issue any input would be greatly appreciated, because its really killing my attention span here at work. I keep fixing other things first, just so I don't have to deal with this...
Rekreativc
 
Posts: 6
Joined: Wed Sep 10, 2008 9:16 am UTC

Re: Coding: Fleeting Thoughts

Postby wing » Fri Dec 19, 2008 9:30 pm UTC

Rekreativc wrote:wow, this is really bothering me atm ... I can't find a way to "discover" if a scroll bar is present in list view ( C# )... What really bothers me is that Form class has a bool property indicating the presence of either, vertical or horizontal scroll bar, and list view doesn't have one ... sux

anyway, if someone has any idea about this issue any input would be greatly appreciated, because its really killing my attention span here at work. I keep fixing other things first, just so I don't have to deal with this...

I don't think there's any direct way, actually.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby elminster » Sun Dec 21, 2008 5:14 am UTC

Quite a long time ago, on my first own project with .NET, I found that you couldn't get images out of webbrowser objects without re-downloading them. I just thought to myself... Why the hell not?!?
I mean, there's lots of other ways (Considerably more long winded) I could get around it and it just seems to be pointless that you can't do that directly; it's already downloaded and cached in memory, why do it again?
Image
elminster
 
Posts: 1382
Joined: Mon Feb 26, 2007 1:56 pm UTC
Location: London, UK, Dimensions 1 to 42.

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Sun Dec 21, 2008 3:19 pm UTC

elminster wrote:Quite a long time ago, on my first own project with .NET, I found that you couldn't get images out of webbrowser objects without re-downloading them. I just thought to myself... Why the hell not?!?
I mean, there's lots of other ways (Considerably more long winded) I could get around it and it just seems to be pointless that you can't do that directly; it's already downloaded and cached in memory, why do it again?

I think you have to search the cache yourself, but I have no clue how to go about doing that sort of stuff in .NET, being a Java programmer myself.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you
User avatar
headprogrammingczar
 
Posts: 2953
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby btilly » Mon Dec 22, 2008 8:31 pm UTC

elminster wrote:Quite a long time ago, on my first own project with .NET, I found that you couldn't get images out of webbrowser objects without re-downloading them. I just thought to myself... Why the hell not?!?
I mean, there's lots of other ways (Considerably more long winded) I could get around it and it just seems to be pointless that you can't do that directly; it's already downloaded and cached in memory, why do it again?

I don't use .NET, but I would not be surprised if you didn't have to make the call to download, and then behind the scenes that call would return the cached object if it was still in cache and valid. The reason for that design would be to avoid having to rewrite the caching logic in multiple places.
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.
btilly
 
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby AttackAttack » Mon Dec 22, 2008 10:39 pm UTC

...I'm getting tired of Python. No, actually, I'm getting SICK of Python. It doesn't "feel" like I think is should. Maybe I'm just not supposed to be a programmer, but Python honestly feels like a toy, a joke. The syntax is simple, yeah, and it's really nice to do things quickly, but I want something that looks like a language. I think I'll go read up on Ruby or Scheme...Even Swaroop C.H., who wrote 'A Byte Of Python', says that Ruby is almost as good as Python. Python is just for super-beginner programmers or really smart programmers who want to do things fast. I'm starter than the average noob, I think, so I'll try it...Yeah, I know it's a stupid reason. But it's not school, so I don't need to do it if I don't like it...

Also; I'm going to download some source codes and make art out of them. I don't know where to start, or what I'll do, but hey, I want to do it. Maybe I'll try Pidgin first...
User avatar
AttackAttack
 
Posts: 27
Joined: Fri Dec 12, 2008 1:31 am UTC

Re: Coding: Fleeting Thoughts

Postby wing » Tue Dec 23, 2008 2:38 am UTC

AttackAttack wrote:...I'm getting tired of Python. No, actually, I'm getting SICK of Python. It doesn't "feel" like I think is should. Maybe I'm just not supposed to be a programmer, but Python honestly feels like a toy, a joke. The syntax is simple, yeah, and it's really nice to do things quickly, but I want something that looks like a language. I think I'll go read up on Ruby or Scheme...Even Swaroop C.H., who wrote 'A Byte Of Python', says that Ruby is almost as good as Python. Python is just for super-beginner programmers or really smart programmers who want to do things fast. I'm starter than the average noob, I think, so I'll try it...Yeah, I know it's a stupid reason. But it's not school, so I don't need to do it if I don't like it...

Also; I'm going to download some source codes and make art out of them. I don't know where to start, or what I'll do, but hey, I want to do it. Maybe I'll try Pidgin first...

I cannot recommend Ruby. It is primarily just a sexy little fad right now. I've heard absolute horror stories from everyone I know trying to use it to accomplish anything other than trivialities or toy projects. Go learn Perl, or a compiled language. Diversify.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Qoppa » Tue Dec 23, 2008 3:30 am UTC

I should learn Perl some time... Or some other language once I'm done with Haskell (well not done with, but comfortable with). Actually, I should probably get around to learning shell scripting some time...

FT: I've successfully implemented bubble sort in Haskell! Horray!
Code: Select all
_=0,w=-1,(*t)(int,int);a()??<char*p="[gd\
~/d~/\\b\x7F\177l*~/~djal{x}h!\005h";(++w
<033)?(putchar((*t)(w??(p:>,w?_:0XD)),a()
):0;%>O(x,l)??<_='['/7;{return!(x%(_-11))
?x??'l:x^(1+ ++l);}??>main(){t=&O;w=a();}
User avatar
Qoppa
 
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby btilly » Tue Dec 23, 2008 4:05 am UTC

wing wrote:I cannot recommend Ruby. It is primarily just a sexy little fad right now. I've heard absolute horror stories from everyone I know trying to use it to accomplish anything other than trivialities or toy projects. Go learn Perl, or a compiled language. Diversify.

Define trivialities and toy projects, please.

My impression from learning the language and from friends who work with it suggest that Ruby is fine at the 50K project stage if you have competent developers. A 50K Ruby project can accomplish quite a bit. If you work on a 3 million line code-base, they will seem like "toys", but businesses are built on such toys. There are, of course, many Ruby projects (particularly Ruby on Rails ones) that lack competent developers. And that will suck no matter how small you make the project.

The only significant things that Perl has over Ruby IMO is a better selection in CPAN, and the availability of the strict macro that forces just enough declaration to catch most of my silly typos. Oh right, and a lot more jobs available.

In any case Perl, Ruby and Python share pretty much the same space, so if you know Python and are looking to diversify your knowledge base, I wouldn't suggest either of the other two. Instead learn a different kind of language. Examples include Java, C, Scheme and Haskell. If, on the other hand, you simply don't like Python, then learn either of the other two because they have different "feels" and people often like one more than another. If you are looking for employability at a junior level, you could learn PHP and hope the experience does not scar you for life.

(Disclaimer, I am an expert-level Perl programmer but I try not to let it bias me too much.)
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.
btilly
 
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby '; DROP DATABASE;-- » Tue Dec 23, 2008 5:06 am UTC

Confession: I really dislike Python's syntax too. I can't remember enough of it to recall exactly what the issues were that annoyed me, but I remember having to do like foo.foo(tuple[bar, baz]) when it would have made a lot more sense to just write foo(bar, baz), or something along those lines.
wing wrote:Also, MWAHAHAHA, I'VE PROGRAMMED A SATELLITE CLOCK. BILLIONS OF DOLLARS OF TECHNOLOGY AND ATOMIC CLOCKS THROWN UP IN ORBIT, EQUATIONS INVOLVING FUCKING RELATIVITY, AND I'M USING IT AS A CLOCK.

... Those little rushes of power when you complete your excessively simple initial test for implementation of a vast, complicated system are awesome, aren't they?

I've reduced the entire GPS constellation to a desktop clock for this one.
Yeah, I get that with simple test/"hello world"-style programs for game consoles. All this CPU and GPU power, sound system, real-time clock, etc etc... and I've got it displaying static like a TV! Wow! How utterly useless... and awesome! :P
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.
User avatar
'; DROP DATABASE;--
 
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy

Re: Coding: Fleeting Thoughts

Postby AttackAttack » Tue Dec 23, 2008 8:38 pm UTC

I actually tried a few Ruby tutorials and like them a lot more than anything I've ever done with Python. Maybe it's just the way I learned it, or maybe Ruby is actually the devil and is trying to lure me away from a perfectly good language, but shoot, I'm lovin' it.
If you are looking for employability at a junior level, you could learn PHP and hope the experience does not scar you for life.

I'm not looking for employability. Yet. I want to learn one simple language and do a lot with it before I learn a "mindfuck language"(even though I suppose Python could be one), just to see if I really want to get more into programming. Diversifying my knowledge base, making myself employable, gaining credibility as a programmer; none of that matters to me right now. I just want to learn a language to see if I can learn to like others. It's not that big a deal to me.

...However, Haskell does seem quite interesting, just because people here seem to like it for Project Euler...

I wonder if it's normal that coding makes me incredibly hungry?
User avatar
AttackAttack
 
Posts: 27
Joined: Fri Dec 12, 2008 1:31 am UTC

PreviousNext

Return to Coding

Who is online

Users browsing this forum: Farpappestals and 11 guests