← Back to context

Comment by quotemstr

4 months ago

Representative example:

  //!malloc
  f(a,y(x+2,WS+=x;c*s=malloc(y);*s++=0;*s++=x;s))     //!< (a)llocate x bytes of memory for a vector of length x plus two extra bytes for preamble, set refcount to 0
                                                      //!< and vector length to x in the preamble, and return pointer to the 0'th element of a new vector \see a.h type system
  f(_a,WS-=nx;free(sx-2);0)                           //!< release memory allocated for vector x.
  G(m,(u)memcpy((c*)x,(c*)y,f))                       //!< (m)ove: x and y are pointers to source and destination, f is number of bytes to be copied from x to y.
                                                      //!< \note memcpy(3) assumes that x/y don't overlap in ram, which in k/simple they can't, but \see memmove(3)
  //!memory management
  f(r_,ax?x:(++rx,x))                                 //!< increment refcount: if x is an atom, return x. if x is a vector, increment its refcount and return x.
  f(_r,ax?x                                           //!< decrement refcount: if x is an atom, return x.
         :rx?(--rx,x)                                 //!<   if x is a vector and its refcount is greater than 0, decrement it and return x.
            :_a(x))                                   //!<   if refcount is 0, release memory occupied by x and return 0.

Reminds me a bit of both the IOCCC and 70s Unix C from before anyone knew how to write C in a comprehensible way. But the above is ostensibly production code and the file was last updated six months ago.

Is there some kind of brain surgery you have to undergo when you accept the q license that damages the part of the brain that perceives beauty?

Lol no. It's just Arthur Whitney style C (with the repo in question being originally written by Whitney).

Whitney kind of set the stage for this but it got adopted informally as a style by the people at IPSA (I. P. Sharp Associates) and spread throughout the industry.

Whitney style C isn't great for everything but it's not bad for interpreter writing and other text/stream touching tasks.

author of the annotated version here.

> representative example

this is grossly taken out of context (which is explicitly stated at the very top of the corresponding readme, https://github.com/kparc/ksimple).

ioccc is often brought up in such HN rants, but the comparison is off mark completely. if you can't read this, you're better off writing some python or some such. this works exactly because it is not obfuscated. this code can't be more regular. tripwires (lack of malloc errno check, possible overflow of refcount) are given as exercises.

> Is there some kind of brain surgery you have to undergo when you accept the q license that damages the part of the brain that perceives beauty?

this code has absolutely zero to do with commercial system k4/kdb+, where did you get that idea? this is published under MIT license. would you like to be reminded of the terms, or fancy an explanation of what they mean? all of them implicitly state that if you're unhappy with the terms you're very welcome to walk away.

hopefully, no brain surgery required for you, god forbid. just an open mind, in methaphorical sense, healthy sense of humour and common sense that the less you type the more you think.

you are also welcome to share examples of code which tickle your sense of beauty, authored by you or someone else.

now, stand straight and defend your argument. we're all ears.