Site seem to be down. `Error establishing a database connection`
Show HN: Writing an HTTP server in Prolog
61–70 of 74 posts
Re: Show HN: Writing an HTTP server in Prolog
#62Earlier quoted context omitted.
Inference is straightforward using dictionaries, membership-testing, and set methods, like subset, superset, disjoint, union, intersection, and difference. Python can't do a conditional assignment as nicely as Prolog's unification, but you can get similar behavior via the application of predicates in comprehensions and using set methods. I'm not saying Python is equivalent, but simply that you can get some of Prolog'…
I appreciate you taking the time. Your approach shows the first steps towards building an inference engine in Python, but these are all very trivial examples. The difference between this and a real logic language will become apparent as the database of facts and rules becomes more complicated. In order to follow this through, you would need to separate all of search code (i.e. the comprehensions) from the declaration…
If you want to write top-down, defining what a mother is before defining who are parents and who are female, then you'll need to write functions and it gets trickier in Python. The sticking point is when to transition from functions to dict/set -- what's a predicate and what's a fact. We could get fancy with decorators to create some funky predicate class, but let's stay away from metaprogramming for the moment.
I agree that Python (without getting fancy) requires the programmer to think through a bit more of the inferential logic than Prolog would under some circumstances. How often do those circumstances arise in practical problems? I'm not sure.
However, I've got to accept the challenge: "What is a list with 30 unique integer elements that sum to 100?"
First, there is no list with 30 unique positive integers that sum to 100.
>>> sum(range(30))
435
Allowing negatives would create an infinity of possible solutions. So, I'm going to rephrase the problem: Generate a list of N unique positive integers that sum to M. >>> from itertools import combinations
>>> m = 30
>>> n = 5
>>> combos = (c for c in combinations(range(m), n) if sum(c) == m)
>>> next(combos)
(0, 1, 2, 3, 24)Re: Show HN: Writing an HTTP server in Prolog
#63Earlier quoted context omitted.
There's at least one language (Refal: there may be more!) based on Markov algorithms. Another language (XL: as far as I know this is the only one of its breed thus far) works at its core on parse tree substitution. Yet another (CHR) does a weird generalization of term re-writing to provide a toolkit for making constraint languages. (Yes, a language to make languages.) There's a reason I've become a programming langua…
>(Yes, a language to make languages.) Are there any other languages that are mainly designed with the goal of making it easier to make other general-purpose languages (as opposed to languages for DSLs or parser generation etc.)? I know that generally many languages are written in C or compile to C, and that Lisp can also be used to make other languages or sub-languages. But asking about languages (mostly) dedicated f…
If I had to write a C or C++ compiler from scratch, I'd do it in Lisp. That project probably wouldn't work in the usual "language inside Lisp" way; it would spit out assembly code or object files which then have nothing to do with Lisp.
The GNU people who originally wrote GCC (Stallman, et al) wanted to use Lisp; they write in C instead because it was well supported on Unix-like system. Stallman is a Lisper; he was on the ANSI CL committee and of course is well known for the Emacs work.
GCC internals are full of Lisp terminology and "Frankenstein monster" versions of Lisp data structures.
As an example, someone posted the following link on Reddit, in the Japanese subreddit:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=28251d450e034f...
It's a GCC commit, whose message discusses the optimization using Lisp notation. The C code doesn't look like Lisp, but the comment explains what it's doing as an S-exp.
Re: Show HN: Writing an HTTP server in Prolog
#64Earlier quoted context omitted.
Chris Granger's Eve is based on Datalog. Perhaps his work is finally what breaks out the logic programming prolog paradigm.
Chris Granger is charismatic, but not particularly insightful. It would be better if he found a mentor.
Re: Show HN: Writing an HTTP server in Prolog
#65Earlier quoted context omitted.
>(Yes, a language to make languages.) Are there any other languages that are mainly designed with the goal of making it easier to make other general-purpose languages (as opposed to languages for DSLs or parser generation etc.)? I know that generally many languages are written in C or compile to C, and that Lisp can also be used to make other languages or sub-languages. But asking about languages (mostly) dedicated f…
People sometimes say ML is aimed at compiler writing.
Re: Show HN: Writing an HTTP server in Prolog
#66Earlier quoted context omitted.
>(Yes, a language to make languages.) Are there any other languages that are mainly designed with the goal of making it easier to make other general-purpose languages (as opposed to languages for DSLs or parser generation etc.)? I know that generally many languages are written in C or compile to C, and that Lisp can also be used to make other languages or sub-languages. But asking about languages (mostly) dedicated f…
Lisp is used for making languages that can usually be all used together in the same project and even mixed together. If I had to write a C or C++ compiler from scratch, I'd do it in Lisp. That project probably wouldn't work in the usual "language inside Lisp" way; it would spit out assembly code or object files which then have nothing to do with Lisp. The GNU people who originally wrote GCC (Stallman, et al) wanted t…
Interesting, did not know they wanted to use Lisp for GCC, though I've read some about Stallman's work.
Edit:
Makes sense, I guess. I've read that functional languages are well-suited to the domain of writing language compilers. Seems logical, because a transformation from, say, a C program to assembly or machine code, can be thought of as a function call:
y = f(x)
where x is the C program, y the machine code, and f the compiler :)
"Stallman is a Lisper; he was on the ANSI CL committee and of course is well known for the Emacs work."
True.
Re: Show HN: Writing an HTTP server in Prolog
#67Earlier quoted context omitted.
Lisp is used for making languages that can usually be all used together in the same project and even mixed together. If I had to write a C or C++ compiler from scratch, I'd do it in Lisp. That project probably wouldn't work in the usual "language inside Lisp" way; it would spit out assembly code or object files which then have nothing to do with Lisp. The GNU people who originally wrote GCC (Stallman, et al) wanted t…
"The GNU people who originally wrote GCC (Stallman, et al) wanted to use Lisp; they write in C instead because it was well supported on Unix-like system." Interesting, did not know they wanted to use Lisp for GCC, though I've read some about Stallman's work. Edit: Makes sense, I guess. I've read that functional languages are well-suited to the domain of writing language compilers. Seems logical, because a transformat…
http://git.savannah.gnu.org/cgit/bash.git/tree/unwind_prot.c
Firstly, the non-local jumps that handle Ctrl-C in Bash and whatnot are referred to using the "unwind protect". Then see the comment in that file:
/* I can't stand it anymore! Please can't we just write the
whole Unix system in lisp or something? */
:)Re: Show HN: Writing an HTTP server in Prolog
#68Earlier quoted context omitted.
>(Yes, a language to make languages.) Are there any other languages that are mainly designed with the goal of making it easier to make other general-purpose languages (as opposed to languages for DSLs or parser generation etc.)? I know that generally many languages are written in C or compile to C, and that Lisp can also be used to make other languages or sub-languages. But asking about languages (mostly) dedicated f…
Lisp is used for making languages that can usually be all used together in the same project and even mixed together. If I had to write a C or C++ compiler from scratch, I'd do it in Lisp. That project probably wouldn't work in the usual "language inside Lisp" way; it would spit out assembly code or object files which then have nothing to do with Lisp. The GNU people who originally wrote GCC (Stallman, et al) wanted t…
What did he do there?
Re: Show HN: Writing an HTTP server in Prolog
#69Earlier quoted context omitted.
Lisp is used for making languages that can usually be all used together in the same project and even mixed together. If I had to write a C or C++ compiler from scratch, I'd do it in Lisp. That project probably wouldn't work in the usual "language inside Lisp" way; it would spit out assembly code or object files which then have nothing to do with Lisp. The GNU people who originally wrote GCC (Stallman, et al) wanted t…
Stallman was member of X3J13? What did he do there?
[update: no]
Richard Gabriel's and Guy Steele's Evolution of Lisp lists Stallman among the people in a "Common Lisp Group".
See: https://www.dreamsongs.com/Files/Hopl2.pdf (P. 21)
Steele's CLTL (1) gives a list of people who were involved in the actual ANSI XJ13, but Stallman isn't listed.
Stallman, however, is credited in that very same book and section as having worked on an implementation of the "New Error System" (NES) as follows: "A reimplementation of the NES for non-Symbolics Lisp Machine dialects (MIT, LMI, and TI) was done at MIT by Richard M. Stallman. During the process of that reimplementation, some conceptual changes were made which have significantly influenced the Common Lisp Condition System."
There you go: Stallman is noted as having been part of an early "Common Lisp Group", and did some implementation work which influenced the CL condition system.
Re: Show HN: Writing an HTTP server in Prolog
#70Earlier quoted context omitted.
Stallman was member of X3J13? What did he do there?
Am I mis-remembering something? [update: no] Richard Gabriel's and Guy Steele's Evolution of Lisp lists Stallman among the people in a "Common Lisp Group". See: https://www.dreamsongs.com/Files/Hopl2.pdf (P. 21) Steele's CLTL (1) gives a list of people who were involved in the actual ANSI XJ13, but Stallman isn't listed. Stallman, however, is credited in that very same book and section as having worked on an implemen…
Stallman never did much work with or on CL. I never had the impression that Stallman was very active in CL design. The mailing list protocols would clear this up...
Stallman actually does not like CL and has critized CL features many times and prevented them to be used in GNU Emacs.
The NES was done at Symbolics. Stallman likely tried to copy it for LMI, while he was fighting against Symbolics. But that phase did not last long.