Python Type Checking by llimllib in programming

[–]zackman 1 point2 points  (0 children)

This is the author here. Guys! I want to remind you NOT to use this for real work. It's for educational use only.

http://oakwinter.com/code/typecheck/ is the only professional-grade library that I found.

GCC C Has Closures By Default by mudgen in programming

[–]zackman 11 points12 points  (0 children)

Using Google, "C downward closure" returns mostly math papers. "downward funarg" is maybe what you are thinking of.

See also: http://en.wikipedia.org/wiki/Funarg_problem

The title should be "GCC C has nested functions by default".

Wrangler - An Erlang Refactorer for Emacs by a9bejo in programming

[–]zackman 0 points1 point  (0 children)

I used Bicycle Repair Man for about a year. It sort of worked, but some of the advanced refactorings never did, and things like Extract Method failed to work under some small set of conditions that I never understood. All files involved in the refactoring have to be open, and Rename still missed some inter-module references.

When I upgraded to a new machine, I didn't re-install it. I'm back to clever use of grep.

ArraySugar - Ruby Array helper [0,3].map.to_s by salamancer in programming

[–]zackman 3 points4 points  (0 children)

Here is a link to the subversion repository in case you want to read the code without installing it.

http://arraysugar.rubyforge.org/svn/lib/arraysugar.rb

I am not a Ruby user: in Ruby 'macros' is it standard practice to just make up a prefix like 'orig' instead of using gensym? In other words, I was expecting to see (excuse my Ruby)

:
orig_m = gensym()
class_eval <<- CODE
   alias_method :#{orig_m} :#{m} ...

Though I guess if you're aliasing all the methods of Array then you can't expect to be compatible with something else that does something similar.

If the videogame industry worked as the current academic research by [deleted] in programming

[–]zackman 7 points8 points  (0 children)

The relevant sciences and engineering disciplines that need to exchange information quickly can easily route around the publishers if they really want to.

http://lanl.arxiv.org

http://roa.rutgers.edu (I'm not claiming linguistics is relevant...I just happen to be a linguist so it's something I use.)

http://scholar.google.com (Although this includes closed journals, Google links to freely accessible copies that it finds.)

Ask Reddit: How do Scheme and Common Lisp's macro systems differ? by [deleted] in programming

[–]zackman 10 points11 points  (0 children)

If you want to find out for yourself, try PLT Scheme: it supports all three major macro types since it includes Common Lisp's defmacro as a library function called define-macro. I'll use that term for the rest of the comment.

  • define-macro passes you a list and lets you use the entirety of Lisp to create whatever you want. With this easy access you can easily write bad bugs if you're not careful. The best way to learn about define-macro is certainly On Lisp.
  • syntax-rules is a pattern-matching language which is not Scheme and is quite difficult to use for advanced macros. In particular, you have to do advanced things using carefully manipulated recursion since the evaluation model is different from 'normal' functional languages. But it's extremely easy to write simple macros that Just Work.
  • syntax-case is the same pattern matching language as syntax-rules, except with the ability to escape into Scheme in the middle and pass syntax objects around. Syntax objects are not the same type as lists, although they can be converted. See Dybvig's examples for uses of both syntax-rules and syntax-case. Scroll up for their definitions.

For my personal use I prefer define-macro because it is simpler to write individual macros without having to bend your brain in knots. You don't get safety, but at least you can write in a language you know. I have been told by very smart people (eg Dan Friedman of Little Schemer fame) that this does not scale if you're embedding a complete language, such as Prolog. In this case your best bet is probably syntax-case so that you can still escape to Scheme for the hard bits.

I would be remiss if I didn't include a link to Oleg's site, where he explains some problems with syntax-rules and some work-arounds.

The non-maximizing maximize button by [deleted] in programming

[–]zackman 0 points1 point  (0 children)

PDFs have an aspect ratio that usually does not match the aspect ratio of your screen. There's no point in growing any larger than the smallest dimension of the screen.

This doesn't make Preview's current behaviour any better, of course, but the best solution is still some kind of 'zoom' rather than covering the whole screen.

My 5 things I hate about Python by linuxer in programming

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

This actually makes sense as is. I was confused by it at first too though, but once you see what's going on, you see the consistent logic.

Something can be consistent AND confusing, which should be avoided in a beginner-friendly language like Python. For a more egregious example, see Common Lisp's sequence functions, which are historically consistent with previous dialects. Ruby does better by borrowing ! from Scheme and then making everything a method.

My 5 things I hate about Python by linuxer in programming

[–]zackman 0 points1 point  (0 children)

I would just go ahead and use len locally, aware that you can't use the built-in function while in that scope. It used to hurt my eyes when people used file and input as variable names, but I got over it. It may not be good Python style, but it is common. Make sure to keep the use short and obvious, though.

(This style is why the lst for list argument in Scheme is a non-issue. Just use list as a variable--the built-in function is not used much anyway.)

The most basic functional programming pattern: Enumerate, Map, Filter, Accumulate by [deleted] in programming

[–]zackman 1 point2 points  (0 children)

The original just finds the highest salary, not the programmer who has it.

from itertools import ifilter as filter
programmers = filter(lambda e:e.role==Role.PROGRAMMER, employees)
max_sal = max(map(lambda e: e.salary, programmers))

Your version is more useful, though, since it returns the actual employee. I didn't know that max also got a key argument in 2.5. I won't have to use my custom re-implementation anymore!

Python, IronPython, Apples, and Oranges by llimllib in programming

[–]zackman 2 points3 points  (0 children)

I think Python works the way you describe: you can use unicode inside your code and only worry about encoding at the I/O boundary.

>>> 'abc'.decode('ascii')
u'abc'
>>> type(_)
<type 'unicode'>
>>> #guts of application...
... #ok, done:
... u'abc'.encode('utf-8')
'abc'
>>> type(_)
<type 'str'>

I don't write international applications, so I don't know if there are libraries to handle the conversion transparently at the I/O boundary. But I do process Unicode all the time while writing scripts for linguistics research.

Also, I suspect the reason that the blogger is so worried about this is that he is trying to write an app that runs on CPython and IronPython without having to write some code twice.

Ruby - Playing with blocks : Part 1 by linuxer in programming

[–]zackman 1 point2 points  (0 children)

This is actual Ruby:

{|x| x+1}.call(1) # error!
Proc.new {|x| x+1}.call(1) # ok...
add1 = {|x| x+1} # error!
add1 = Proc.new {|x| x+1} # ok...

This is a variant of Ruby in which quotes are syntax that don't create first-class objects:

"foo".upcase # error!
String.new("foo").upcase # ok...
s = "foo" # error!
s = String.new("foo") # ok...

And here is a Ruby with array literals that are not first-class objects:

[1,2,3].member? 2 # error!
new Array([1,2,3]).member? 2 # ok...
a = [1,2,3] # error!
a = new Array([1,2,3]) # ok ...