Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Jul 25, 2009 12:53 pm UTC

Yeah, seems mostly basic data structure knowledge and some easy algorithm smithery.

-edit-

My functional language is actually coming along almost disturbingly well. A lot of the features are theoretical or sketchily implemented at the moment, but it's list-oriented like LISP, stack-oriented like Forth (but in polish notation, instead of reversed -) and pattern-matching like Haskell (except it matches against the stack).

Here are some syntactical examples:

Code: Select all

# A function that sums all numbers on the stack
        define [ top @rest ] sum         + top sum rest ;
        define [ top ] sum         top ;
# The following function would calculate a factorial:
        define [ 0 @rest ] fac                1 rest;
        define [ n @rest ] fac                * n [ fac + -1 n ] rest;
# The following duplicates the topmost element on the stack:
        define [ top @rest] dup            top top rest;
# Did I mention that truth values are also operators?
        define [ [ expression condition ] @rest ] select
             condition expression
             select rest;
        define [ [ expression condition ] ] select
             condition expression;

        select [ [ say hello ] [ > 5 2 ] ]
               [ [ say does-not-compute ] [ < 5 2 ] ];



-- edit --

I also just noticed that this is the 1,000:th reply to this thread. Happy post-iversary Fleeting Thoughts.
Last edited by You, sir, name? on Thu Jul 30, 2009 12:41 am UTC, edited 3 times in total.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
levicc00123
Posts: 165
Joined: Thu Jan 03, 2008 5:33 pm UTC
Location: Sterling, CO
Contact:

Re: Coding: Fleeting Thoughts

Postby levicc00123 » Wed Jul 29, 2009 1:37 pm UTC

Has anyone played with the abc module that came with python 2.6?
Image

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jul 30, 2009 12:44 am UTC

You, sir, name? wrote:
Spoiler:
Yeah, seems mostly basic data structure knowledge and some easy algorithm smithery.

-edit-

My functional language is actually coming along almost disturbingly well. A lot of the features are theoretical or sketchily implemented at the moment, but it's list-oriented like LISP, stack-oriented like Forth (but in polish notation, instead of reversed -) and pattern-matching like Haskell (except it matches against the stack).

Here are some syntactical examples:

Code: Select all

# A function that sums all numbers on the stack
        define [ top @rest ] sum         + top sum rest ;
        define [ top ] sum         top ;
# The following function would calculate a factorial:
        define [ 0 @rest ] fac                1 rest;
        define [ n @rest ] fac                * n [ fac + -1 n ] rest;
# The following duplicates the topmost element on the stack:
        define [ top @rest] dup            top top rest;
# Did I mention that truth values are also operators?
        define [ [ expression condition ] @rest ] select
             condition expression
             select rest;
        define [ [ expression condition ] ] select
             condition expression;

        select [ [ say hello ] [ > 5 2 ] ]
               [ [ say does-not-compute ] [ < 5 2 ] ];


-- edit --

I also just noticed that this is the 1,000:th reply to this thread. Happy post-iversary Fleeting Thoughts.


I'm seriously intimidated by my own creation. It's grammar is ridiculously small and simple, yet I can't seem to find anything I can't implement trivially. In fact, I've had to remove a whole bunch of features because they were so simple to implement in the language that they became redundant. Like, I said truth values were operators. They were operators. I realized that you can implement that language yourself in only the following 2 short lines, so I removed it as a hard-coded feature.

Code: Select all

define [ @rest ] true   rest;
define [ @rest ] false   ;


I'm also considering dropping the number part, and making it strictly symbol-oriented. Which would further reduce the rule set to only only creation and expansion of definitions.

I secretly hope there is some horrible design problem that makes all this a pipe dream. A programming language with fewer rules than can be counted the fingers of a single hand should by definition be a turing tarpit.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Thu Jul 30, 2009 2:00 am UTC

Lambda calculus has very few rules as well, but is a perfectly fine language to program in (given a bit of syntactic sugar). Haskell is basically lambda calculus + data structures + sugar (+ types).
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.

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

Re: Coding: Fleeting Thoughts

Postby fazzone » Thu Jul 30, 2009 2:41 am UTC

You, sir, name? wrote:...

What does the factorial function look like? Or factoring an integer or something like that. Can you do any of the Euler problems in it yet?
*/

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jul 30, 2009 3:22 am UTC

fazzone wrote:
You, sir, name? wrote:...

What does the factorial function look like? Or factoring an integer or something like that. Can you do any of the Euler problems in it yet?


Here's what the factorial function looks like.

Code: Select all

        define [ 0 ] fac                1;
        define [ n ] fac                * n fac [ + n -1 ];


You can also create Haskell style infinite sequences

Code: Select all

        define [ x ] inf                x [ inf [ + x 1 ] ];


Evaluates to a list of n, n+1, n+2, n+3, n+4, n+5, ...

I haven't tried any of the Euler problems, mostly because I have a few design issues to make up my mind about, but I'll get there soon enough...
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
xulaus
Posts: 136
Joined: Thu Jul 03, 2008 11:09 am UTC

Re: Coding: Fleeting Thoughts

Postby xulaus » Thu Jul 30, 2009 11:45 am UTC

You, sir, name? wrote:...
Please keep us posted on this language, it seems like it might be awsome when finished.
Meaux_Pas wrote:I don't even know who the fuck this guy is

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Thu Jul 30, 2009 4:10 pm UTC

I just wrote a Brainfuck interpreter! Yay! Sort of makes me want to try writing a Scheme interpreter or something next. On a side note, how would I go about turning my interpreter into a compiler?

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
InkL0sed
Posts: 205
Joined: Wed Sep 10, 2008 3:46 am UTC

Re: Coding: Fleeting Thoughts

Postby InkL0sed » Thu Jul 30, 2009 4:44 pm UTC

That'd be harder. Basically, you'd have to convert the program into assembly code, then compile that.

EDIT: Actually, since it's brainfuck, you could compile it into C code, then run your C compiler on it. Or Java, C++, whatever it is you're more comfortable with.

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Thu Jul 30, 2009 4:56 pm UTC

That's sort of what I figured. I may have a go at it if I feel up to 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
Area Man
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: Coding: Fleeting Thoughts

Postby Area Man » Thu Jul 30, 2009 6:11 pm UTC

Yeah, writing an actual compiler is srs bsns. It's not something you slap on to a interpreter, it's quite a different task. Code-rewriting(translating) and handing it off to a real compiler is much easier.

You could write a front-end parser for gcc, too.
Bisquick boxes are a dead medium.

User avatar
Vault
Posts: 169
Joined: Mon Nov 10, 2008 5:00 pm UTC
Location: Just past the event horizon
Contact:

Re: Coding: Fleeting Thoughts

Postby Vault » Thu Jul 30, 2009 6:50 pm UTC

You could also check out LLVM.

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Coding: Fleeting Thoughts

Postby ash.gti » Thu Jul 30, 2009 7:18 pm UTC

The llvm is a lot more cleanly organized and easier to extend than GCC. There is a project to tie the JIT features of the LLVM into python which is proving pretty successfully (although the developers said that memory consumption is up 10x) its called unladen swallow. Also the MacRuby project is doing the same thing with ruby and it too is proving pretty successful and giving ruby a pretty decent speed boost.
# drinks WAY to much espresso

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jul 30, 2009 7:21 pm UTC

xulaus wrote:
You, sir, name? wrote:...
Please keep us posted on this language, it seems like it might be awsome when finished.


Excerpts from an actual session with the interpreter:

Code: Select all

 > define [ 0 ] fac   
        1.

 > define [ n ] fac
        * n [ fac [ + n -1 ] ] .

 > fac 20.
(...a screen of debug info later...)
 [ 2432902008176640000  ]
 >
...
>
 > define [ 0 ] seq 0.

 > define [ n ] seq n [ seq [ + n -1 ] ] .

 > + seq 10 .
 [ 55  ]
 > + seq 1000000.
(20 seconds later)
 [ 500000500000  ]
 >



-- edit -- got lambda functions partially implemented. Some demonstrations:

Spoiler:

Code: Select all

> define [ [ @operator ] top @rest ] map
        [ @operator top ] map operator @rest .
> define [ [ @operator ] last ] map
        [ @operator last ] .
> + map [ ,\ [ a ] [ % a 5 ] ] 1 2 3 4 5 6 7 8 9 10 .
[ 20 ]

 > define [ x x ] = true .
 > define [ x y ] = false .
> define [ cond @statement ] if
        ,\ [ =true @statement ] [ @statement ] cond @statement .
> if [ = 10 20 ] print Mathematics is a lie!.
> if [ = 10 10 ] print Mathematics is correct after all.
[ Mathematics is correct after all ]


-- edit -- It just gets better and better. I realized that if I allow patterns to match symbols against other patterns, I can not only parse pretty much any grammar, I can also allow a type system to be implemented -in- the language*, and still have it feel as natural as anything. (I've also moved to a more lisp-like syntax in general, but that's not what's important)

The new pattern syntax is symbol:pattern. In substitution, it prefixes the pattern's name to the values of the pattern. Et voila, types in a type-less language.

Code: Select all

define ( =Vector x y z ) Vector
        ( Vector x y z ) ;
       
define ( =Scalar r ) Scalar
        ( Scalar r ) ;

define ( v:Vector ) print
       print ( v.x v.y v.z ) ;

define ( s:Scalar ) print
       print ( s.r ) ;

define ( a:Vector b:Vector ) addv
        ( Vector ( + a.x b.x ) ( + a.y b.y ) ( + a.z b.z ) ) ;
       
define ( a:Vector ) norm2
        ( Scalar ( + ( * a.x a.x ) ( * a.y a.y ) ( * a.z a.z ) ) ) ;
       
define ( a:Vector b:Vector ) dot
        ( Scalar ( + ( * a.x b.x ) ( * a.y b.y ) ( * a.z b.z ) ) ) ;



* I now have a language that ships with only pattern matching and expansion system, and some basic arithmetics, and yet can pull off conditional statements (if, if-else, select, etc.), lisp-style list manipulation functions (cdr, car, cons, etc.), maps / folds / zips / unzips, and now finally types.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Sun Aug 02, 2009 9:50 pm UTC

I suppose I could just code up a quick test program to find out, but does anyone know what happens if you call ftell() on a file when the current location exceeds the size of a long (the return type)? Does it return a -1, or does it overflow?

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
jaap
Posts: 2077
Joined: Fri Jul 06, 2007 7:06 am UTC
Contact:

Re: Coding: Fleeting Thoughts

Postby jaap » Sun Aug 02, 2009 9:55 pm UTC

Qoppa wrote:I suppose I could just code up a quick test program to find out, but does anyone know what happens if you call ftell() on a file when the current location exceeds the size of a long (the return type)? Does it return a -1, or does it overflow?


I don't think it is specified. That is why there are the fgetpos and fsetpos functions which can handle large files.

User avatar
InkL0sed
Posts: 205
Joined: Wed Sep 10, 2008 3:46 am UTC

Re: Coding: Fleeting Thoughts

Postby InkL0sed » Sun Aug 02, 2009 10:19 pm UTC

You, sir, name? wrote:
xulaus wrote:
You, sir, name? wrote:...
Please keep us posted on this language, it seems like it might be awsome when finished.


Excerpts from an actual session with the interpreter:

Code: Select all

 > define [ 0 ] fac   
        1.

 > define [ n ] fac
        * n [ fac [ + n -1 ] ] .

 > fac 20.
(...a screen of debug info later...)
 [ 2432902008176640000  ]
 >
...
>
 > define [ 0 ] seq 0.

 > define [ n ] seq n [ seq [ + n -1 ] ] .

 > + seq 10 .
 [ 55  ]
 > + seq 1000000.
(20 seconds later)
 [ 500000500000  ]
 >



-- edit -- got lambda functions partially implemented. Some demonstrations:

Spoiler:

Code: Select all

> define [ [ @operator ] top @rest ] map
        [ @operator top ] map operator @rest .
> define [ [ @operator ] last ] map
        [ @operator last ] .
> + map [ ,\ [ a ] [ % a 5 ] ] 1 2 3 4 5 6 7 8 9 10 .
[ 20 ]

 > define [ x x ] = true .
 > define [ x y ] = false .
> define [ cond @statement ] if
        ,\ [ =true @statement ] [ @statement ] cond @statement .
> if [ = 10 20 ] print Mathematics is a lie!.
> if [ = 10 10 ] print Mathematics is correct after all.
[ Mathematics is correct after all ]


-- edit -- It just gets better and better. I realized that if I allow patterns to match symbols against other patterns, I can not only parse pretty much any grammar, I can also allow a type system to be implemented -in- the language*, and still have it feel as natural as anything. (I've also moved to a more lisp-like syntax in general, but that's not what's important)

The new pattern syntax is symbol:pattern. In substitution, it prefixes the pattern's name to the values of the pattern. Et voila, types in a type-less language.

Code: Select all

define ( =Vector x y z ) Vector
        ( Vector x y z ) ;
       
define ( =Scalar r ) Scalar
        ( Scalar r ) ;

define ( v:Vector ) print
       print ( v.x v.y v.z ) ;

define ( s:Scalar ) print
       print ( s.r ) ;

define ( a:Vector b:Vector ) addv
        ( Vector ( + a.x b.x ) ( + a.y b.y ) ( + a.z b.z ) ) ;
       
define ( a:Vector ) norm2
        ( Scalar ( + ( * a.x a.x ) ( * a.y a.y ) ( * a.z a.z ) ) ) ;
       
define ( a:Vector b:Vector ) dot
        ( Scalar ( + ( * a.x b.x ) ( * a.y b.y ) ( * a.z b.z ) ) ) ;



* I now have a language that ships with only pattern matching and expansion system, and some basic arithmetics, and yet can pull off conditional statements (if, if-else, select, etc.), lisp-style list manipulation functions (cdr, car, cons, etc.), maps / folds / zips / unzips, and now finally types.


I think I'd like to play with this, once you think it's ready. Do you think you'll write a compiler?

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Sun Aug 02, 2009 10:21 pm UTC

jaap wrote:I don't think it is specified. That is why there are the fgetpos and fsetpos functions which can handle large files.
Well I need it to get the number of bytes in the file, so I don't think fgetpos will be all that useful.

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
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Mon Aug 03, 2009 12:20 pm UTC

InkL0sed wrote:I think I'd like to play with this, once you think it's ready. Do you think you'll write a compiler?


I'm not sure if I'll write a compiler. There doesn't seem to be any significant overhead in parsing the language.

My main focus right now is designing the language to be as clear as possible. The entire language is designed in way where both the interpreter and programmer can easily understand the language. It is completely devoid of syntactic sugar, so the only difference between what you see and what the interpreter sees is that you see a string of text, and the interpreter receives that text in a tree form (the creation of which is like 50 lines of C code).
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Mon Aug 03, 2009 4:47 pm UTC

You should write a compiler in the language itself, then compile it with itself running on the C interpreter. No self-respecting language would do otherwise.
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
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Mon Aug 03, 2009 10:02 pm UTC

Of course. That is the only proper way of making sure a language works.

On a semi-related topic, I've used my language to implement arguably the ugliest primality test in existence:

Code: Select all

define ( n ) isprime
        != 0
                ( * map
                        ( % n )
                        ( sequence 2 ( + n -1 ) )
                );


Not only is it broken (it loops forever if n <= 2), it's ridiculously slow. Testing the first 1000 numbers if they are primes takes like ~30 seconds. Not that it really works with numbers > ~100. Beyond that point, it breaks from integer overflow and starts yielding the wrong results.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
InkL0sed
Posts: 205
Joined: Wed Sep 10, 2008 3:46 am UTC

Re: Coding: Fleeting Thoughts

Postby InkL0sed » Mon Aug 03, 2009 11:17 pm UTC

Sounds wonderful.

User avatar
phlip
Restorer of Worlds
Posts: 7550
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Tue Aug 04, 2009 2:43 am UTC

Borland wrote:Error reading property MainForm->Visible: the window does not have scroll bars.

Some days, I really don't like this IDE...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

L337R3dN3k
Posts: 65
Joined: Sun Jul 26, 2009 6:37 am UTC

Re: Coding: Fleeting Thoughts

Postby L337R3dN3k » Wed Aug 05, 2009 5:17 am UTC

You, sir, name? wrote:I also just noticed that this is the 1,000:th reply to this thread. Happy post-iversary Fleeting Thoughts.


And this is the 1024th post. w00t!

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

Re: Coding: Fleeting Thoughts

Postby fazzone » Wed Aug 05, 2009 11:19 am UTC

Yeah, but this is the 1024th reply.
*/

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Wed Aug 05, 2009 11:51 am UTC

Why is it that all the good code libraries are proprietary? The GUI system used by Valve Software (VGUI) is a multiplatform C++ library that is thread-safe, supports localization, and renders on the desktop as well as in-game using an overlay, and can be rendered on any 2D surface in the 3D world, and interacted with by the player. Unfortunately, Valve limits the use of VGUI to non-employees to only be usable in-game, which automatically makes its platform independence meaningless! What the hell? I thought I had finally found a GUI library that didn't suck, and this is what I get?
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

Hijax
Posts: 32
Joined: Thu Jul 09, 2009 7:51 am UTC

Re: Coding: Fleeting Thoughts

Postby Hijax » Wed Aug 05, 2009 5:35 pm UTC

headprogrammingczar wrote:Why is it that all the good code libraries are proprietary? The GUI system used by Valve Software (VGUI) is a multiplatform C++ library that is thread-safe, supports localization, and renders on the desktop as well as in-game using an overlay, and can be rendered on any 2D surface in the 3D world, and interacted with by the player. Unfortunately, Valve limits the use of VGUI to non-employees to only be usable in-game, which automatically makes its platform independence meaningless! What the hell? I thought I had finally found a GUI library that didn't suck, and this is what I get?

answer: get work at valve and secretly steal the library, then quit. problem solved(illegally).
Blag, crap, junk, and other stupid stuff, at the junkpile
Image
Starter of the quiche eating initiative:
The owner of this signature votes yes for quiche eating, and is proud about it. If you do too, copy and paste this text into your signature.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Wed Aug 05, 2009 5:39 pm UTC

Hijax wrote:
headprogrammingczar wrote:Why is it that all the good code libraries are proprietary? The GUI system used by Valve Software (VGUI) is a multiplatform C++ library that is thread-safe, supports localization, and renders on the desktop as well as in-game using an overlay, and can be rendered on any 2D surface in the 3D world, and interacted with by the player. Unfortunately, Valve limits the use of VGUI to non-employees to only be usable in-game, which automatically makes its platform independence meaningless! What the hell? I thought I had finally found a GUI library that didn't suck, and this is what I get?

answer: get work at valve and secretly steal the library, then quit. problem solved(illegally).


... because an corporate espionage conviction is that little extra spice that makes your CV stand out in the crowd. ;-)

---

:-/ Had to re-write my language interpreter. Mostly because the first incarnation is a pile of crap. On the upside, the re-write is in Java, which is good for a whole host of reasons. Something like 90% of the issues with the C interpreter stemmed from memory management issues, with a tradeoff between spending 95% of runtime garbage collecting, or having the garbage collector crash/corrupt memory 10% of the times. Now I can delegate mess that to Java instead.

The real nice thing is that aggressive graph reduction will be incorporated as a fundamental feature of the interpreter, which amusingly enough should make it run a lot faster than the C interpreter ever did.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Fri Aug 07, 2009 4:08 am UTC

So I've been working on my hex editor lately, and I now have a functioning gui implemented. Yay! My next course of action is to allow the user to actually modify the files, but I'm not sure how to best implement this... Inserting or deleting in place will be hugely inefficient since the file is just loaded into a giant char arary, so I'm trying to think of a better way. Any ideas? Perhaps I should split the file into smaller portions so that when I shift for insertions and deletions, I'm not shifting as huge of an array?

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
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Fri Aug 07, 2009 4:23 am UTC

Qoppa wrote:So I've been working on my hex editor lately, and I now have a functioning gui implemented. Yay! My next course of action is to allow the user to actually modify the files, but I'm not sure how to best implement this... Inserting or deleting in place will be hugely inefficient since the file is just loaded into a giant char arary, so I'm trying to think of a better way. Any ideas? Perhaps I should split the file into smaller portions so that when I shift for insertions and deletions, I'm not shifting as huge of an array?


I guess you could create some sort of table of aliased locations. I think it's best explained with an example. Say you have a memory chunk with 4 letters "ABCD" in the same order as they occur in the file. Then your alias table would look like

start -> 0-3 -> end

Then you want to add a "QWE" between A and B. Your memory chunk is now "ABCDQWE", and your alias table looks like

start-> 0, 4-7, 1-3 -> end

.... well, you get the picture. When the table gets too long, commit the changes to a pristine buffer. It should be faster than rampant memcpying, especially if the file is very large.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Coding: Fleeting Thoughts

Postby Random832 » Fri Aug 07, 2009 11:46 am UTC

Most hex editors I've used don't allow insertion or deletion at all. (It's too easy to do by accident and the file formats people typically use hex editor on aren't safe to shift things around in). Maybe start with just allowing users to overwrite characters without moving them?

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Coding: Fleeting Thoughts

Postby Qoppa » Fri Aug 07, 2009 4:18 pm UTC

Random832 wrote:Most hex editors I've used don't allow insertion or deletion at all. (It's too easy to do by accident and the file formats people typically use hex editor on aren't safe to shift things around in). Maybe start with just allowing users to overwrite characters without moving them?
Well implementing that is pretty trivial since I already have a cursor, so I decided to look at the more difficult problem first so that if I need to do any radical changes, I won't have to redo anything afterwards. You're right though, maybe I don't even need to add the ability to insert or delete... If I do, YSN's method seems like it would work pretty well, but I'll think about it a bit before doing anything. Experience tells me that planning ahead is incredibly useful and can save you tons of grief.

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
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Fri Aug 07, 2009 5:07 pm UTC

Qoppa wrote:
Random832 wrote:Most hex editors I've used don't allow insertion or deletion at all. (It's too easy to do by accident and the file formats people typically use hex editor on aren't safe to shift things around in). Maybe start with just allowing users to overwrite characters without moving them?
Well implementing that is pretty trivial since I already have a cursor, so I decided to look at the more difficult problem first so that if I need to do any radical changes, I won't have to redo anything afterwards. You're right though, maybe I don't even need to add the ability to insert or delete... If I do, YSN's method seems like it would work pretty well, but I'll think about it a bit before doing anything. Experience tells me that planning ahead is incredibly useful and can save you tons of grief.


If you do implement insertions and deletions, you'll probably want to do it from a context menu or something like that, since it would indeed be pretty dangerous to have text editor-style insertion and deletion.

Anyways, with proper implementation hiding, you shouldn't have any headache if you decide to add such features.


On a not quite related sidenote, does anyone have any resources on code design methodology? I've gotten to a point where my design algorithm
  • Make a prototype.
  • Find problems with prototype.
  • Goto 1.
while it works reasonably well (largely due to the intuition for coding I've developed), is really cumbersome. Preferably somewhere that isn't too rigid and corporate.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Fri Aug 07, 2009 6:23 pm UTC

Code design basically boils down to making a list of features and implementing them separately. Don't plan ahead, or your features might gain dependencies. Make wrappers. Larger projects always end up with the same design, no matter how much it's designed in advance; some call it organic, others call it modular. That is assuming there's any design left at all.
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
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Emu* » Fri Aug 07, 2009 6:32 pm UTC

Sounds like Agile programming, but without the pointy-haired-boss aspects...
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
PM 2Ring
Posts: 3636
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Fri Aug 07, 2009 7:01 pm UTC

Berengal wrote:Don't plan ahead, or your features might gain dependencies. Make wrappers.
It's hard to disagree with this philosophy. If you don't use a black box approach, you are in danger of creating spaghetti.

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Coding: Fleeting Thoughts

Postby Robert'); DROP TABLE *; » Sat Aug 08, 2009 9:36 pm UTC

Code: Select all

cout << particles[i].position.x << "   " << particles[i].position.y << "   " << i <<  endl;

is necessary for my program, and I can't work out why. It's that specific statement, since if it's uncommented, everything works fine, and there are no control structures nearby.
...And that is how we know the Earth to be banana-shaped.

Rysto
Posts: 1459
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Coding: Fleeting Thoughts

Postby Rysto » Sat Aug 08, 2009 9:50 pm UTC

Your problem is likely due to timing(unlikely unless you're using threads), stack corruption or using an uninitialized variable from the stack. Compile your program with -Wall and fix any warnings. If that doesn't fix your problem, try running your program in valgrind.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Aug 08, 2009 9:59 pm UTC

It could also be junk from something that isn't compiled thoroughly. Try doing a clean re-compile.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
InkL0sed
Posts: 205
Joined: Wed Sep 10, 2008 3:46 am UTC

Re: Coding: Fleeting Thoughts

Postby InkL0sed » Sat Aug 08, 2009 11:14 pm UTC

How would I do an animation in a Java Swing GUI? I don't mean just adding a gif file, I'm thinking more like having a BufferedImage displayed in a JPanel or something, and having the view update whenever I change a pixel on the BufferedImage.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests