Recently I was involved in a project that required producing a CSV file as output. To convert the output in Microsoft Excel format, I used Google Docs where I uploaded the CSV file and exported it as a .xls. When trying to open the file from Excel, one would get the following (not very helpful) message:

SYLK: File format is not valid

SYLK are files typically used to exchange data between applications. Fortunately, Microsoft has documented the problem:

A SYLK file is a text file that begins with “ID” or “ID_xxxx”, where xxxx is a text string. The first record of a SYLK file is the ID_Number record. When Excel identifies this text at the beginning of a text file, it interprets the file as a SYLK file. Excel tries to convert the file from the SYLK format, but cannot do so because there are no valid SYLK codes after the “ID” characters. Because Excel cannot convert the file, you receive the error message.

The quick workaround to the above is to not use “ID” as the first two characters in the CSV file to be imported. And like the article says, this problem does not occur if the first two letters are lowercase “i” and “d”.

Ah, the joys of report generating. Full of slight annoyances…

c-client callbacks

2010/12/17

* This is mostly for personal copy-paste reasons

Those who take the time to develop applications using UW-IMAP (or Panda IMAP) know that there are a number of callbacks that need to be defined. What follows is the simplest (do nothing) version of them.

#include "c-client.h"

void
mm_flags(MAILSTREAM *stream,unsigned long number) {
}

void
mm_status(MAILSTREAM *stream,char *mailbox,MAILSTATUS *status) {
}

void
mm_searched(MAILSTREAM *stream,unsigned long number) {
}

void
mm_exists(MAILSTREAM *stream,unsigned long number) {
}

void
mm_expunged(MAILSTREAM *stream,unsigned long number) {
}

void
mm_list(MAILSTREAM *stream,int delimiter,char *name,long attributes) {
}

void
mm_lsub(MAILSTREAM *stream,int delimiter,char *name,long attributes) {
}

void
mm_notify(MAILSTREAM *stream,char *string,long errflg) {
}

void
mm_log(char *string,long errflg) {
}


void
mm_dlog(char *string) {
}

void
mm_login(NETMBX *mb,char *user,char *pwd,long trial) {
}

void
mm_critical(MAILSTREAM *stream) {
}

void
mm_nocritical(MAILSTREAM *stream) {
}

long
mm_diskerror(MAILSTREAM *stream,long errcode,long serious) {
}

void
mm_fatal(char *string) {
}

Remember that it is written in “The Roots of Lisp” that:

If you want a language for describing algorithms, you might want something more abstract, and that was one of McCarthy’s aims in defining Lisp.

It was only after Steve Russell programmed eval (in machine code) that Lisp became a tool for the keyboard rather than a tool for pen and paper.

From the SWI-Prolog mailing list: “Coding Guidelines for Prolog“. There’s also interesting commentary on the list, but has not yet appeared in the list archives.

Dimitris posted over at twitter a list of “Top funny source code comments” as compiled by Vinícius Krolow. Unfortunately /* You are not expected to understand this */ is not there. Fortunately, DMR explains it in “Odd Comments and Strange Doings in Unix“.

I am sure other lists of really cool comments exist and this thread over at StackOverflow seems to be collecting them.

decreasoner is a Discrete Event Calculus reasoner written by Erik T. Mueller (author of “Commonsense Reasoning“). This is how I build it on OpenBSD 4.7:

  • tar zxf ply-3.3.tar.gz
  • tar zxf decreasoner.tar.gz
  • cd decreasoner/software/relsat-dist/
  • tar zxf ../../../relsat_2.02.tar
  • gmake -f Makefile.linux
  • cp ./relsat ../../solvers/
  • cd ../..
  • cp ../ply-3.3/ply/lex.py .
  • cp ../ply-3.3/ply/yacc.py .
  • decreasoner.py executes sort -g. Unfortunatelly, OpenBSD’s sort does not support a -g switch and you have to change it to -n. See also a discussion of sort -g vs sort -n.
  • ./make.sh

Someday I think I may contribute a script that may (semi)automate the above…

C interpreters

2010/09/03

I spotted today on Hacker News an article about PicoC, a small C interpreter. This triggered my memory in a journey back in 1994 when I had asked over at comp.compilers whether any C interpreter existed. It was then that I learned about ICI, a cool C-like scripting language that deserves more attention, the Quincy C interpreter which evolved to an IDE, and Smac, the C-like
interpreter that comes embedded with the XCoral editor.

Then there are also CINT which is part of an even more interesting project, and of course Ch.

But the coolest interpreter that I’ve seen, is written by Diomidis Spinellis:

#include "/dev/tty"

It changed the rules for the IOCCC.

loop

2010/07/16

for (i = 0; i < strlen(string); i++) {
  :
}

This is a C version of a loop that I recently bumped into while copy-pasting some code. In the above loop strlen(string) is called strlen(string) times instead of just once (unless the length of string changes while in the loop):

int len;
:
len = strlen(string);
for (i = 0; i < len; i++) {
  :
}

Unless the compiler detects this and optimizes the loop, this is very bad practice. Yes, most of the compilers do detect this, but this does not mean that the programmer must rely on the compiler's optimizations. What if it does not get optimized in the end?

This is not a rant about wasted CPU cycles. It is mostly a rant about laziness in our thinking.

For those who have not heard Greenspun’s Tenth Rule, it states that:

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

By the way, Greenspun‘s rules 1 to 9 do not exist.

Seven months ago, during a discussion about Prolog, I asked Ozan S. Yigit to reformulate Greenspun’s tenth rule for Prolog. Oz replied:

Any sufficiently complicated modern program contains a buggy, informal implementation of prolog that casual observers confuse with lisp.

Just hours earlier I was basically a listener in a discussion that involved NoSQL. While clearly I am not a NoSQL advocate, I am no hater either, but what I heard lead me to the following reformulation of Greenspun’s rule, this time involving the relational model:

Those who blindly adopt #NoSQL will discover a variation of Greenspun’s tenth rule

I am sure that many other variations exist. In fact the Wikipedia page on Greenspun’s Tenth Rule contains a Prolog variation similar to Ozan’s and an Erlang version. So if you know of (or can make up) any other, please post it here (or somewhere).

Stateful protocols

2010/05/02

Mark Crispin writes:

“In particular, doing things with mailboxes in the hundreds of MB in that format takes a while. The authors of Outlook and Thunderbird are victims of a computer science course mindset which, starting in the 1980s, taught their pupils that all protocols are (or should be) stateless. Thus, they believe that IMAP is like HTTP; that when a server fails to respond immediately, that means that the correct remedial action is to disconnect and try again, or just disconnect and assume that everything happened anyway.”

[via imap-uw]

Follow

Get every new post delivered to your Inbox.

Join 1,104 other followers