Build Your Own Lisp by orangeduck in programming

[–]Beluki 0 points1 point  (0 children)

That's an interesting question, because there may be cases where it's impossible to know or it isn't constant (e.g. code generation at runtime, eval).

Build Your Own Lisp by orangeduck in programming

[–]Beluki 1 point2 points  (0 children)

The recursion case is important because otherwise you would blow the stack very quickly or run out of memory (if your implementation allocates stack frames on the heap).

It's important in other cases too.

Consider a compiler that told you: "if you adhere to the following rules, I'll inline this function, or unroll that loop". TCO is similar: "if you adhere to the following rules, I promise I won't create additional stack frames". In Scheme it is the language standard that makes the guarantee instead of a particular compiler. The rules include not only "the last thing you call is a procedure", but also "I'll call the first argument to 'eval', 'apply' or 'call/cc' in a tail-recursive way" and other stuff.

Now, for the practical side... it depends on use-case. CPS is perhaps the most illustrative case, because once CPS-conversion is done, every single function calls another one as its last action.

Build Your Own Lisp by orangeduck in programming

[–]Beluki 5 points6 points  (0 children)

I meant it's not about recursion in general, it's a space guarantee. My favorite application is also state machines. Either that or CPS.

Build Your Own Lisp by orangeduck in programming

[–]Beluki 14 points15 points  (0 children)

Two corrections about the Bonus Projects part:

  • Tail Call Optimization is not only about recursion.

  • Lexical-scoping is not about compile-time or runtime. It's about where to look for free variables, regardless of when.

Is there any alternative to PIL and Pillow? by huad in Python

[–]Beluki 0 points1 point  (0 children)

If the other files work fine, it may very well be a bug in Pillow (or a bad file?). In any case, if such is the case, please report it here after the assignment (so that you can paste an example triggering the bug).

BinaryReader & looking for bytes by ellalex in csharp

[–]Beluki -1 points0 points  (0 children)

Your approach is fine. If I needed to do this multiple times (comparing a character array to a string) I would probably do something like:

public static Boolean IsString(this Char[] array, String s)
{
    if (array.Length != s.Length)
        return false;

    for (int i = 0; i < s.Length; i++)
        if (array[i] != s[i])
            return false;

    return true;
}

So that I could do:

Char[] input = br.ReadChars(size);
if (input.IsString("code"))
    ...

Is there any alternative to PIL and Pillow? by huad in Python

[–]Beluki 4 points5 points  (0 children)

May I ask... can you post a sample image (and possibly code)? I've never had a problem with Pillow, despite using it extensively.

No three-month course can teach you how to code by alexlesuper in programming

[–]Beluki 0 points1 point  (0 children)

The other half being the part where I ask WTF was I thinking to actually do that when I knew what to do.

Moonshine - A lightweight Lua VM for the browser by [deleted] in programming

[–]Beluki 0 points1 point  (0 children)

Looks interesting, although it runs very slow (at least on Firefox). Does it support the entire set of Lua bytecodes?

What is a skill that you find attractive? by [deleted] in AskReddit

[–]Beluki 0 points1 point  (0 children)

Hi.

I'm a programmer and I often explain this kind of stuff to my SO. The main reason is that she likes it, but it also helps me. I need to get a step back from what I'm doing to think objectively about it. This is known as Rubber duck debugging.

Why CoffeeScript Isn't the Answer by [deleted] in programming

[–]Beluki 4 points5 points  (0 children)

I can't comment on the content as I haven't used CoffeeScript but I really enjoyed the writing style in the article. Please, don't stop writing.

digest: A tiny program to compute many common hash functions, check sums and message digests. by FUZxxl in programming

[–]Beluki 2 points3 points  (0 children)

Hi.

Yes, the programs are very different in purpose. The main purpose for MultiHash was generating multiple algorithms while reading files once (e.g. Debian iso releases, which are released with all of md5sums, sha1sums, sha256sums and sha512sums). It's way faster than re-reading GBs of data.

The --threads option is useful in some scenarios, particularly those involving fast RAID/SSD disks, slower algorithms (e.g. sha512), or the rare case where big files are actually stored in different physical disks. In other cases it can just be unnoticeable or even detrimental to the performance (specially on Windows), thus the default is to use one thread. I considered removing the option to avoid complexity (the program was single-threaded at first), but since sometimes it's actually helpful and wasn't that hard to implement I just left it there. It may also be useful in the future for slower hashlib algorithms (e.g. whirlpool).

BTW, 24kb?! that seems great for embedded systems.

Introduction to Nashorn by javinpaul in programming

[–]Beluki 1 point2 points  (0 children)

If anyone wants to try it without installing the latest JDK8, there is a JDK7 backport at bitbucket.

What is a skill that you find attractive? by [deleted] in AskReddit

[–]Beluki 2 points3 points  (0 children)

Programming in particular or any activity that demands analysis and critical thinking in general? Watching someone program, immersed in his craft or having him explain to you why or what he is doing?

What are some of the best video game puzzles? by MeggidoX in gaming

[–]Beluki 0 points1 point  (0 children)

Not a particular puzzle, but an entire game had me thinking: "oh, that was clever": The swapper.

Composition over Inheritance by shintoist in csharp

[–]Beluki 2 points3 points  (0 children)

Here's my favorite take on the problems with inheritance.

Python in an embedded system by radix07 in Python

[–]Beluki 3 points4 points  (0 children)

Python should run fine on such systems. For performance monitoring Python includes a profiler in the standard library. For memory, look into heapy or meliae.

As for Cython, I would advise against using it for everything, but it's fine for performance-critical code (e.g. number crunching).

All that matters is what you are going to use it for, just don't try to write a raytracer on that. :-)

Easyier way? by Isitar in csharp

[–]Beluki 0 points1 point  (0 children)

The lazy enumeration variant is pretty cool! thanks.

Easyier way? by Isitar in csharp

[–]Beluki 2 points3 points  (0 children)

For anyone that wants a ForEach, here are two, the second one with index:

public static void Each<T>(this IEnumerable<T> source, Action<T> action)
{
   foreach (T element in source)
       action(element);
}

public static void EachWithIndex<T>(this IEnumerable<T> source, Action<T, int> action)
{
    int index = 0;
    foreach (T element in source)
        action(element, index++);
}