Hacker News new | past | comments | ask | show | jobs | submit login

Tcl is extremely straightforward once you figure it out:

http://antirez.com/articoli/tclmisunderstood.html

'for' is a command that takes 4 arguments:

    {set i 1} - eval'ed once at start time.
    { $i <= 100 } - an expression that is checked each time to determine whether to continue
    { incr i } - eval'ed each time
    { ... the rest ... } the body is eval'ed each time.
Everything in Tcl is like that - it's extremely easy to figure out and there are no surprises. It's also extremely easy to implement. Here's Hecl's for loop:

    case FOR:
    /* The 'for' command. */
    /* start */
    interp.eval(argv[1]);
    /* test */
    while (Thing.isTrue(interp.eval(argv[2]))) {
	try {
	    /* body */
	    interp.eval(argv[4]);
	} catch (HeclException e) {
	    if (e.code.equals(HeclException.BREAK)) {
		break;
	    } else if (e.code.equals(HeclException.CONTINUE)) {
	    } else {
		throw e;
	    }
	}
	/* next */
	interp.eval(argv[3]);
    }
    break;



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: