flabberghaster

flabberghaster wrote

I'm kind of surprised they're that hard to work with. I've never used one, just hasn't come up in any of the projects i've been on; But i'd expect them to have some escape hatch. Something where you'd be able to just give it an SQL query you want to run, as a prepared statement or something, tell it some variables to put in, maybe tell it what types it would return, depending on the language, and just have it run it.

Do they not? Or is it just impractical to use somehow?

2

flabberghaster wrote

I think that it's basically a special case of how in those languages it's easy to assign a reference to things. Adding a list to itself is not really that different than assigning a reference to an object as a member of itself. For instance in python you can do:

class Node:
    __init__(self, value, next=None):
        self.value = value
        self.next = next

def main():
    head = Node("last")
    tail = head
    for i in range(10): head = Node(i, head)
    tail.next = head

And this creates a cyclic linked list. You could just as easily assign a = Node(9); a.next = a and have the graph have only one vertex. It's the same principle with adding a list to itself: you're not actually adding the list to itself; rather you're putting a reference to the container, inside the container. Like writing down the location of a bank on a slip of paper, then putting that slip of paper inside a safe deposit box stored inside the same bank.

3

flabberghaster wrote

Turns out python can too. I was trying to think of how to get c++ to do it, but i could only think if how to do it using void pointers since to add something to a container that container would have to be a container of its own type which I can't think how to do off the top of my head.

Interesting problem.

3