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

Pages: 1-4041-

Pointers in other languages

Name: Anonymous 2011-08-18 8:49

So I've been using C for almost a year now but decided to give Python a chance. Python and many high level languages don't have pointers like C. Without pointers how do you implement dynamic data structures like lists and trees? (I know that Python has these built in but what if I want to use a more specific structure not built in)

Name: Anonymous 2011-08-18 8:54

You can't! Learning Python comes along with forgetting "real" languages.

Try C++ if you want a (sometimes) moar powerfull language.

Name: Anonymous 2011-08-18 10:12

"Faggot" [sic] languages don't need ponters because their objects are reference (not passed by value etc) values and the languages have GC.

Name: Anonymous 2011-08-18 10:45

In Lisp one implements lists and trees using recursive nesting of conses. It is practically identical to the C way, but with garbage collection.
Python doesn't have lists. What they call lists are in fact dynamic arrays.

Name: Anonymous 2011-08-18 11:45

Write it in C, the functions take PyObject * parameters.

Name: Anonymous 2011-08-18 15:32

Python dynamic arrays are more cache-efficient than cons trees or lists. Prove me wrong.

Name: Anonymous 2011-08-18 15:52

>>6
too bad its reference is being stored in a hash table

Name: Anonymous 2011-08-18 16:08

>>7
Not buying it.

Name: Anonymous 2011-08-18 16:24

>>8
you wouldn't buy FREE SOFTWARE

Name: Anonymous 2011-08-18 20:30

>>9
That's like saying you wouldn't buy FREE BEER

I buy beer all the time, and in addition to money it has cost me my friend, family, marriage, career and dignity.

Name: Anonymous 2011-08-18 21:05

<- Look at my doubles.

Name: Anonymous 2011-08-18 23:11

>>1
You can implement linked lists using closures. Closures can be used for lots of schtuff.

Name: Anonymous 2011-08-19 0:03

>>12
clojures can be used for lots of stuff, too

Name: Anonymous 2011-08-19 1:14

>>1
In other languages, pointers are implicit for reference types allocated on the heap. Underneath, it works just like pointers, but without the syntax or need to free memory you've allocated.

Name: Anonymous 2011-08-19 2:39

function LinkedList() {
   
    var Node = function(data) {
        this.data = data;
        this.next = null;
    };
   
    var length = 0;
    var head;
   
    this.add = function(data) {
        var node = new Node(data);
       
        if (!head) {
            head = node;
        } else {
            current = head;
            while (current.next !== null) {
                current = current.next;
            }
            current.next = node;
        }
       
        length++;
        return this;
    };
   
    this.get = function(index) {
        if (index < 0 || index > length) {
            return null;
        }
       
        var current = head;
        for (var i = 0; i < index; i++) {
            current = current.next;
        }
        return current.data;
    };
   
    this.remove = function(index) {
        if (index < 0 || index > length) {
            throw new Error("index " + index + " out of bounds");
        }
                   
        if (index == 0) {
            head = head.next;
        }
        else {
            var before = head;
            for (var i = 1; i < index; i++) {
                before = before.next;
            }
            before.next = before.next.next;
        }
       
        length--;
        return this;
    };
}

Name: Anonymous 2011-08-19 8:16

>>15
What language is this?

Name: Anonymous 2011-08-19 8:19

>>16
Perl.

Name: Anonymous 2011-08-19 8:27

>>16
Look's like Javascript.

Name: Anonymous 2011-08-19 8:46

>>18
No.

Name: Anonymous 2011-08-19 9:00

>>19
Yes.

Name: Anonymous 2011-08-19 9:13

class LinkedList:
    class Node:
        def __init__(self, elem):
            self.elem = elem
            self.next = None

    class Iterator:
        def __init__(self, node):
            self.current = node

        def next(self):
            if self.current.next == None:
                raise StopIteration

            self.current = self.current.next

            return self.current.elem

    def __init__(self):
        self.dummy = LinkedList.Node(None)
        self.size  = 0

    def add(self, e):
        node = self.dummy

        while node.next != None:
            node = node.next

            if node.elem == e:
                return False

        node.next  = LinkedList.Node(e)
        self.size += 1

        return True

    def addAll(self, c):
        changed = False

        for e in c:
            if self.add(e):
                changed = True

        return changed

    def clear(self):
        self.dummy.next = None

    def __contains__(self, o):
        for e in self:
            if (o == e):
                return True

        return False

    def containsAll(self, c):
        for o in c:
            if not o in self:
                return False

        return True

    def __len__(self):
        return self.size

    def __iter__(self):
        return LinkedList.Iterator(self.dummy)

    def isEmpty(self):
        return self.dummy.next == None

    def remove(self, o):
        node = self.dummy

        while node.next != None:
            if node.next.elem == o:
                node.next  = node.next.next
                self.size -= 1
                return True

            node = node.next

        return False

    def removeAll(self, c):
        changed = False

        for o in c:
            if self.remove(o):
                changed = True

        return changed

Name: Anonymous 2011-08-19 9:14

POINTER MY ANUS

Name: Anonymous 2011-08-19 9:14

of course that's not Perl, come on

Name: Anonymous 2011-08-19 9:15

of course that's not LISP, come on

Name: Anonymous 2011-08-19 9:15

>>21
Of course that is THE FORCED INDENTATION OF CODE THREAD OVER come on.

Name: Anonymous 2011-08-19 9:17

If you want to specialize some built-in data structure in Python you inherit from it.

Name: Anonymous 2011-08-19 9:17

>>25
I chortled.

Name: Anonymous 2011-08-19 9:18

ooc.util.LinkedList

By the way every ooc object is compatible for use with Python.

Name: Anonymous 2011-08-19 9:28

>>28
ooc
Get out.

Name: Anonymous 2011-08-19 9:33

>>28
Python
Get in.

Name: Anonymous 2011-08-19 9:39

Anus
Get haxed.

Name: Anonymous 2011-08-19 9:40

>>29

#include <ooc/io/io.h>
#include <ooc/util/LinkedStack.h>

int main(void) {
  var stack = new(LinkedStack());

  Stack$push(stack, "bro?");
  Stack$push(stack, "made ");
  Stack$push(stack, "u ");
  Stack$push(stack, "Why ");

  foreach(char * str, stack) {
    print(str);
  } foreach_end;

  println("");

  del(stack);

  return 0;
}

Name: Anonymous 2011-08-19 9:45

>>29

from ooc.util import LinkedList

myList  = LinkedList()
myList += ["Are", "you", "angry?"]

for s in myList:
  print s,

Name: Anonymous 2011-08-19 9:48

  print s[b],[/b]
Disgusting.

Name: Anonymous 2011-08-19 9:48

>>34
Shit.

Name: Anonymous 2011-08-19 9:50

>>34,35
If you find your own post disgusting please refrain from posting it, at least don't call it shit in a separate post.

Name: Anonymous 2011-08-19 9:53

>>36
SEPARATE MY ANUS

Name: Anonymous 2011-08-19 9:54

>>37
That is extremely difficult, your anus is probably very tight, did you actually mean ``SEPARATE MY BUTTCHEEKS''?

Name: Anonymous 2011-08-19 10:38

>>38
That is extremely difficult, your anus is probably very tight
Not after years of training that allows him to hide a can of condensed milk there!

Name: Anonymous 2011-08-19 11:00

>>32
ooc
Pig disgusting.

>>33
from ooc.util import LinkedList
Nice language, shit import.

Name: Anonymous 2011-08-19 11:43

>>39
Back to Russian imageboards.

Name: Anonymous 2011-08-19 11:52

>>41

Name: Anonymous 2011-08-19 15:38

>>32
int main(void) {
var
new(), del()
return 0;
foreach_end

Okay, what language is this?

Name: Anonymous 2011-08-19 15:40

>>43
BBCode
Multiquote
Fail

Name: Anonymous 2011-08-19 16:11

>>44
BBCodeMultiquoteSuccess

Name: Anonymous 2011-08-19 16:20

>>43
It's ANSI-C.

Name: Anonymous 2011-08-19 16:29

>>46
It's ANUS-C.

Name: Anonymous 2011-08-19 16:30

Name: Anonymous 2011-08-19 16:44

>>48
So there was a male once with an unhaxable anus who then got an anus with surgery?

Name: Anonymous 2011-08-19 16:58

>>4
Python doesn't have lists. What they call lists are in fact dynamic arrays.

I like the part where you made shit up.

Look at the source. They are double linked lists.

Name: Anonymous 2011-08-19 17:29

>>50
Fuck off, jew.

Name: Anonymous 2011-08-19 17:38

>>51
BUTTOWNED

Name: Anonymous 2011-08-19 17:51

>>50
In CPython they're dynamic arrays.

Name: Anonymous 2011-08-19 18:41

>>52
U MENA FIBONACCI BUTTSORTED

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