Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP part V

Name: Anonymous 2008-03-08 8:38

LISP

Name: Anonymous 2008-04-04 0:14

,KX;

Name: Anonymous 2008-04-04 0:23

import os
import sys
import imp

TEMPLATE_DIR = 'theme'


def import_module(name, path):
    filename = os.path.join(path, name.replace('.', '/') + '.py')
    mtime = os.stat(filename)[8]
    module_name = 'template.' + name

    if module_name in sys.modules:
        module = sys.modules[module_name]

        if mtime <= getattr(module, '__mtime__', 0):
            print 'Not reloaded'
            return module

    module = imp.load_source(module_name, filename)
    module.__mtime__ = mtime
    return module


def fetch_template(name, *args, **kwargs):
    tmpl = import_module(name, TEMPLATE_DIR)

    if callable(tmpl.__template__):
        return tmpl.__template__(*args, **kwargs)

    return tmpl.__template__


print fetch_template('comment-form', reference=1)

Name: Anonymous 2008-04-04 2:43

           Why do Python code always look like a parser error?

Name: Anonymous 2008-04-04 3:43

>>403
Because your parser outputs errors in the form of Python code?

Name: Anonymous 2008-04-04 4:52

how do i do this in lisp?
void sort(uintmax_t *numbers, size_t length){
 uintmax_t temp[length];
 uintmax_t *arrays[2] = {numbers, temp};
 for(uint_fast8_t i = 0; i < sizeof(uintmax_t) * CHAR_BIT; ++i){
  for(size_t j = 0, start = 0, end = length - 1; j < length; ++j){
   if(!(arrays[i & 1][j] & 1 << i))
    arrays[i & 1 ^ 1][start++] = arrays[i & 1][j];
   if(arrays[i & 1][length - j - 1] & 1 << i)
    arrays[i & 1 ^ 1][end--] = arrays[i & 1][length - j - 1];
}}}

Name: Anonymous 2008-04-04 7:29

>>405
(ffi-lib "sort.a")

Name: Anonymous 2008-04-04 10:09

>>406
i meant "how do i implemented this algorithm in lisp?", not "how do i called c code from lisp?"

Name: Anonymous 2008-04-04 10:12

>>405
uintmax_t temp[length];
And then..
uintmax_t *arrays[2] = {numbers, temp};
FAIL.
temp is uintmax_t [length], which degrades to uintmax_t [*]
So you need


uintmax_t (*p)[*] = temp;


tl;dr you don't know C.

Name: Anonymous 2008-04-04 10:36

I've been wondering for a ling time: how does lisp read the C or Java or whatever? I mean, it's different syntax and all.

Name: Anonymous 2008-04-04 11:03

>>409
ling
Please learn English.

Name: Anonymous 2008-04-04 11:06

(define (radix-sort list radix)
  (define (vector-mutate! v i f) (vector-set! v i (f (vector-ref v i))))
  (let loop ((list (map cons list list)))
    (if (zero? (apply + (map cdr list)))
        (map car list)
        (do ((list list (cdr list)) (buckets (make-vector radix '())))
          ((null? list) (loop (apply append (map reverse (vector->list buckets)))))
          (vector-mutate!
           buckets (remainder (cdar list) radix)
           (lambda (x) (cons (cons (caar list) (quotient (cdar list) radix)) x)))))))

Now supporting all nonnegative integer lists and all integer radices > 1.

Name: Anonymous 2008-04-04 11:13

LISP

Name: Anonymous 2008-04-04 11:14

>>408
$ cat sort.c
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort(uintmax_t *numbers, size_t length){
 uintmax_t temp[length];
 uintmax_t *arrays[2] = {numbers, temp};
 for(uint_fast8_t i = 0; i < sizeof(uintmax_t) * CHAR_BIT; ++i){
  for(size_t j = 0, start = 0, end = length - 1; j < length; ++j){
   if(!(arrays[i & 1][j] & 1 << i))
    arrays[i & 1 ^ 1][start++] = arrays[i & 1][j];
   if(arrays[i & 1][length - j - 1] & 1 << i)
    arrays[i & 1 ^ 1][end--] = arrays[i & 1][length - j - 1];
}}}

int main(int argc, char *argv[]){
 if(argc>1){
  size_t len=strlen(argv[1]);
  uintmax_t *array = calloc(len,sizeof(uintmax_t));
  for(size_t i=0;i<len;++i) array[i]=(uintmax_t)argv[1][i];
  sort(array,len);
  for(size_t i=0;i<len;++i) argv[1][i]=(char)array[i];
  puts(argv[1]);
 }
 return 0;
}
$ gcc -Wall -ansi -pedantic -std=c99 sort.c; ./a.out 5a7asfgadf34; rm a.out
sort.c: In function `sort':
sort.c:13: warning: suggest parentheses around arithmetic in operand of ^
sort.c:15: warning: suggest parentheses around arithmetic in operand of ^
3457aaadffgs
$


tl;dr you don't know C.

Name: Anonymous 2008-04-04 11:21

>>413
LOL. You're only making a fool of yourself with posting more code that does not work.

Name: Anonymous 2008-04-04 11:22

>>410
HAHAHA I DON'T KNOW HOW TO ANSWER HIM SO I'LL RIDICULE HIS TYPING MISTAKES INSTEAD HURRRRRRR DURRRRRRRRRRR HURRRRRRRRRRR

Name: Anonymous 2008-04-04 11:24

>>414
I found it in Knuth.

Name: Anonymous 2008-04-04 11:24

>>414
And is uglier than the LISP equivalent and also longer.

Holy fuck, I can't believe I said this.

Name: Anonymous 2008-04-04 11:25

>>411
wow, that's ugly. does it still operate in O(n) time and O(n) space?

Name: Anonymous 2008-04-04 11:27

>>417
no one has posted a LISP equivalent.

Name: Anonymous 2008-04-04 11:37

>>415
No, I know.
It's object code. man elf.

Name: Anonymous 2008-04-04 11:38

>>419
Cinnamon Lasp ≠ LISP
Scheme ∈ LISP

Name: Anonymous 2008-04-04 11:41

>>417,419
and the LISP posted by >>411 is longer than the C posted by >>405.

Name: Anonymous 2008-04-04 11:53

LISPEL

Name: Anonymous 2008-04-04 17:43

LISP

Name: Anonymous 2008-04-04 17:47

(apply + (map cdr list) (map car list) (quotient (cdar list) radix) (define (radix-sort list radix) (define (vector-ref v i)))) (let loop ((list (map cons list list))) (if (zero?  buckets (remainder (cdar list) radix) (lambda (x) (cons (cons (cons (cons (caar list) (quotient (cdar list) radix) (lambda (x) (cons (cons (cons (cons (cons (cons (caar list) (do ((list list (cdr list)) (buckets (make-vector radix '()))) ((null?  list) (loop (apply append (map reverse (vector->list buckets))))) (vector-set!  v i f) (vector-mutate!  list) (loop (apply append (map reverse (vector->list buckets)))))

Name: Anonymous 2008-04-04 17:56

>>425
This is why we have FIOC.

Name: Anonymous 2008-04-04 19:01

>>425
Even brackets

Name: Anonymous 2008-04-04 19:29

>>426
Frame I/O Controller?

Name: Anonymous 2008-04-04 19:34

>>428
You have been caught being unfunny.

Name: Anonymous 2008-04-04 22:02

>>425
(cons (cons (cons (cons (cons (cons ...

Name: Anonymous 2008-04-04 23:52

                                                [1]
                                               [1, 1]
                                             [1, 2, 1]
                                            [1, 3, 3, 1]
                                          [1, 4, 6, 4, 1]
                                        [1, 5, 10, 10, 5, 1]
                                      [1, 6, 15, 20, 15, 6, 1]
                                    [1, 7, 21, 35, 35, 21, 7, 1]
                                  [1, 8, 28, 56, 70, 56, 28, 8, 1]
                               [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
                          [1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]
                        [1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1]
                     [1, 12, 66, 220, 495, 792, 924, 792, 495, 220, 66, 12, 1]
                 [1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1]
             [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1]
         [1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, 105, 15, 1]
    [1, 16, 120, 560, 1820, 4368, 8008, 11440, 12870, 11440, 8008, 4368, 1820, 560, 120, 16, 1]
[1, 17, 136, 680, 2380, 6188, 12376, 19448, 24310, 24310, 19448, 12376, 6188, 2380, 680, 136, 17, 1]

Name: Anonymous 2008-04-05 0:13

Name: Anonymous 2008-04-05 2:46

LISP

Name: !o2lispROLE 2008-04-05 6:10


lispROLL                            
                       //`'''```,   
             o        // LISP   `., 
       ,....OOo.   .c;.',,,.'``.,,.`
    .'      ____.,'.//              
   / _____  \___/.'                 
  | / ||  \\---\|                   
  ||__||   \\__||                   
  ˌ´  `ˌ   ˌ´  `ˌ                   
 |  ()  | |  ()  |                  
  `ˌ__ˌ´   `ˌ__ˌ´                   

Name: Anonymous 2008-04-05 19:20

lisp

Name: Anonymous 2008-04-05 23:52

LISP

Name: Anonymous 2008-04-06 8:42

당신의 sicp 지켜 오늘은?
http://www.youtube.com/watch?v=iuv6xZEdMKo

Name: Anonymous 2008-04-06 9:23

LISP

Name: Anonymous 2008-04-06 9:24

    _  ∩
  ( ゚∀゚)彡 Oacos(-1)I Oacos(-1)I!
     ⊂彡

Name: Anonymous 2008-04-06 20:35

LISP

Newer Posts