Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
There is always something like xslt

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Munkeymon posted:

Yes, but median-of-three implementation of QuickSort should protect it against degenerating into N2 time when it is passed a sorted list of any kind (pre-sorted, reverse sorted, 'almost' sorted).

If you're interested in this sort of thing, 'Engineering a Sort Function' by Mcilroy and Bentley is a good read:

http://www.enseignement.polytechnique.fr/informatique/profs/Luc.Maranget/421/09/bentley93engineering.pdf

tef
May 30, 2004

-> some l-system crap ->
launchpad ?

tef
May 30, 2004

-> some l-system crap ->
Use a web app, and output simple html, and use css to make it less ugly?

tef
May 30, 2004

-> some l-system crap ->
It is less about the language and more about the libraries - it depends what level you will have to be parsing the html (text only/html only/ with javascript?).

Most dynamic languages make excellent choices - Perl has LWP::Simple and a few html parsing modules.

Python has beautifulsoup (slow) or lxml to parse html, and urllib2 or pycurl to grab pages.

I'm not sure about ruby, but I'm pretty sure it has similar libraries.

Really, Perl, Ruby or Python are perfectly capable of web crawling.

tef
May 30, 2004

-> some l-system crap ->

hexadecimal posted:

Depending on how complex your parsing needs to be for the webpage, you may or may not need Yacc, but lexer is a pretty nice tool. Also fast as gently caress.

Althugh everyone else has already called you out for this, the reason why I recommended things like beautifulsoup or lxml is that although parsing well formed htm lis easy, html is never well formed.

An HTML parser that supports xpath is a fantastic invention, I think some even support css selectors too.

tef
May 30, 2004

-> some l-system crap ->
Please don't rely on hexadecimal for help.

If you want accurate answers, you're better off posting in the relevant threads.
Hexadecimal is frequently corrected by people who can program in c++.


If you are new to programming, I would learn something like Python, Ruby or Perl. They're a lot easier to pick up than java, and often easier to use straight away.

If you're hardcore - learn scheme, you will learn a lot more but I would say one of the more mainstream dynamic languges might be more approachable.

OO is best learned once you have programs to structure. Java and C# are mutually intelligable dialects, so don't worry too much about picking one or the other.

Overall, you will spend more time learning libraries than you will languages.

tef
May 30, 2004

-> some l-system crap ->

Liquid Silk posted:

Hi guys, I have a PROLOG program to do,

:toot:

quote:

a stupid Eliza type program, and I have various standard replies to keywords, such as animals;

code:
animal_member(X) :- member(X,[dog, dogs, cat, cats, puppy, puppies, 
kitten, kittens, wolf, wolves]).
pattern(List, ['do you have an interest in animals']):- member(X, List), animal_member(X).

Traditionally, this would look something like this:
code:
animal(dog).
animal(dogs).
animal(cat).
animal(cats).
animal(puppy).
...

pattern(List,['animals blah']) :- member(X, List), animal(X).
And it would be faster too - prolog indexes predicates.


quote:

I now have to have a specific, distinct response if the input contains happy feelings AND animals. Anyone have any tips? Tia.

code:
pattern(List,['animals and love']) :- member(X, List), animal_member(X), member(Y,List), happy_member(Y).
pattern(for just happy).
pattern(for just animal).

quote:

Edit: I'm sure this is going to be really easy an answer, but I've been racking my brains and trying all sorts of complications, that I'm going crazy.

Don't try and write an optimal solution, write a simple one first.

I would probably do something* like this:
code:
happy(joy).
happy(love).
....

animal(dog).
animal(cat).

contains_happy(List) :- member(X,List), happy(X).
contains_animal(List) :- member(X,List), animal(X).

pattern(List,['i love animals']) :- contains_happy(List), contains_animal(List).
* Actually I would do something like this:
code:
word(joy, happy).
word(love, happy).
...
word(dog, animal).
word(cat, animal).
...

contains(List,Type) :- member(X, List), word(X, Type).

contains_all(List, []).
contains_all(List, [Type|Tail]) :- contains(List, Type), contains_all(List,Tail).

pattern([happy, animal], ['I love horses! best of all the animals']).

response(List, Answer) :- pattern(Types, Answer), contains_all(List, Types).
But the previous solution would probably be faster :v:

tef fucked around with this message at 17:41 on Jan 14, 2009

tef
May 30, 2004

-> some l-system crap ->
I wrote http://logo.twentygototen.org, and I've been asked to kludge it to make it work with speech recognition.

Right now we're using a hack - a fixed vocabulary in osx' speakable items, that sends the right keys to firefox.

I've been pointed at the following, and it looks like a start: http://www.w3.org/TR/wai-aria/ , but I would be thankful at any other information out there.

The plan is to change from a text-box to an almost command-line like interaction, a bit like working in a shell. We might have to change the syntax slightly to support this.

I'm also looking at proprietary sr software, or a series of convoluted hacks to take it forward.

Does anyone have any experience in speech driven environments ?
or how to hook into osx's speech recognition a little deeper ?
or in general any ideas about how to essentially write a speech driven code editor ?

edit: http://web.archive.org/web/20080213071927/voicecode.iit.nrc.ca/VoiceCode/public/ywiki.cgi

tef fucked around with this message at 06:48 on Jan 27, 2009

tef
May 30, 2004

-> some l-system crap ->
I'm pretty sure CLC intercal allows you to redefine integer literals :eng101:

http://intercal.freeshell.org/
http://esolangs.org/wiki/CLC-INTERCAL
code:
   DO .1 <- .2/#1
   DO .2 <- #3
   DO .1 <- #1

quote:

What happens here? The first assignment introduces overloading of .2, so the second assignment assigns #3 to #1. In other words, from now on every time you say 1 you really mean 3. We have changed the value of a constant, but not just that. Consider the third assignment: this assigns #3 to .3, not #1 to .1, for obvious reasons. This can be a great obfuscation tool.

tef fucked around with this message at 01:50 on Feb 10, 2009

tef
May 30, 2004

-> some l-system crap ->
a warning:

regardless of what question you ask, if it mentions 'text editing' and 'linux' you will get a few responses saying "vim" or "emacs"

these are probably not what you want.


(for example the thread asking for nano syntax highlighting is about 3 pages of vim people and then it breaks into vi vs emacs)

tef
May 30, 2004

-> some l-system crap ->

tef posted:

I wrote http://logo.twentygototen.org, and I've been asked to kludge it to make it work with speech recognition.

....
The plan is to change from a text-box to an almost command-line like interaction, a bit like working in a shell.

I didn't see any help with this so I'll try again but be a little bit more specific.

Currently the logo interpreter works on a 'file at a time' mentality. You pass it a lump of text and it runs it. I want to change this into a more shell-like interaction, i.e. a read, eval, print loop.

How do you write parsers/tokenizers to facilitate REPL's ?

Logo has a few issues that make this a little more awkward, specifically lack of terminators. "fw 100 rt 90" is a valid command. I've cooked up a little hack here
that just checks for things like balanced parenthesis before evaling them.

http://logo.twentygototen.org/static/speech.html

But, I don't get to check the syntax of anything with [] or function definitions with this approach.

What parser designs support this approach?

tef
May 30, 2004

-> some l-system crap ->
Hopping on the pythagorean train:

code:
every (z is 1 .. 200 && y is 1 .. z && x is 1 .. y && 0 is x * x + y * y - z * z && [x y z])

tef fucked around with this message at 09:50 on Mar 21, 2009

tef
May 30, 2004

-> some l-system crap ->

ShoulderDaemon posted:

Please don't write your own encryption software, you'll do it wrong. Find some library that complies with RFC 3852.

This may help: http://www.google.com/search?q=php+gpg

tef
May 30, 2004

-> some l-system crap ->

Dijkstracula posted:

If you don't mind getting your hands dirty with a backtracking logic language like Prolog, this sounds like a good constraint programming problem.

:toot:

(refresher: Variables start with a capital, and atoms (string constants) start with a lowercase letter, and statements end with a period).

in foo.pl:
code:
 
% base case - the pairs of an empty set of elements is the empty list
all_pairs([],[]).
% recursive case
all_pairs(Elements,Pairs):-
    pair(Elements, LeftOver, Out), % make one pair
    all_pairs(LeftOver, NewPairs), % make pairs from the leftovers
    Pairs = [Out|NewPairs]. % add out to the front of new pairs

% find one valid pair
pair(Elements, LeftOver, Out) :-
    Elements = [X|E1],  % take the first item
    select(Y, E1, LeftOver), % take any other item
    can_pair(X,Y), % try to pair them
    Out = [X,Y].

% items can pair if they are in the same group.
can_pair(X,Y) :- 
     element_group(X,T),
     element_group(Y,T).

element_group(hot, temp).
element_group(cold, temp).
element_group(cat, animal).
element_group(dog, animal).
element_group(black, colour).
element_group(white, colour).
in the prolog interpreter:
code:
$ swipl
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.

?- [foo]. % or use consult('foo.pl').
% foo compiled 0.00 sec, 2,180 bytes
true.

?- all_pairs([hot,cold,cat,dog],Boxes).
Boxes = [[hot, cold], [cat, dog]] ;
false.

?- halt.
$
You should be able to add new rules based on can_pair/2 and element_group/2.

You can add new rules like can_pair(foo,Y) :- member(Y, [abacus, zebra, foxtrot]). to say goo can pair with abacus, zebra or foxtrot.

Edit: This is a simple generate and test program. It is possible to optimize this significantly.

tef fucked around with this message at 16:22 on Mar 30, 2009

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

So this simply tells if a set of boxes is allowed or not, based on the constraints of the allowed pairs?

No. It's *generate* and test.

By passing a variable in, it will search for a value that is a valid set of pairs from the given elements:

code:
?- all_pairs([hot,cold,cat,dog],Boxes).
Boxes = [[hot, cold], [cat, dog]] ;
false.
This is generating all the possible combinations of the set [hot, cold, cat, dog].

The trick with prolog is that you simply state what you want, and then prolog finds it for you.

You can also call it with a set and a list of pairs to see if it is a valid combination.

Or call it with a list of pairs and find out the set of elements.

Or call it with two variables to enumerate all possible sets of elements and pairs.

Edit: To give a simpler example: Every prolog expression is really a question:

code:
% is foo a member of the list [foo,bar,baz]
?- member(foo,[foo,bar,baz]).
true . % yes

% is X a member of [foo,bar,baz]
?- member(X,[foo,bar,baz]).
X = foo ; % yes, if X = foo
X = bar ; % yes, if X = bar
X = baz ; % yes, if X = baz
false.    % there are no more ways this can be true

% is foo a member of the list X?
?- member(foo,X).
X = [foo|_G269] ; % yes, if X is a list where foo is the head, and some variable is the tail
X = [_G268, foo|_G272] ; % and so on....

% is X a member of the list Y ?
?- member(X,Y).
Y = [X|_G284] ; % etc, and this also goes on
You write questions in prolog, and write rules to deduct information.

I wrote rules to say that a list of elements and a list of pairs is valid if
it could make one pair, and the rest of the elements could be made into pairs.

The prolog interpreter searches for a possible case where the rule is true. By supplying variables, I can enumerate cases where the rule is true.

The program itself is very trivial and basic prolog, if you can write up the rules
in a pastebin or link to them, I can try to add it to the example I wrote above.

tef fucked around with this message at 16:24 on Mar 30, 2009

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

I guess what I don't get about any of these bits of code, is when the program stops, and where it starts.

In mine it starts by taking two items, trying to pair them, and then moves onto the rest of them.

It stops when it runs out of items to pair, or if it can't pair the remaining items.

In the latter case, it will not produce a solution.

tef
May 30, 2004

-> some l-system crap ->
What is IsAllowed defined as?

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

It returns true if the pair is allowed, and false if the pair is forbidden.

You really have a knack for answering a question without any substance.


This is I think the third time I've asked for your constraints and either you present a different set to the one you want to implement (primes), or in this case you manage to tell me "isallowed" is whether a pair is allowed.


When someone asks for the definition, the mean the code.

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

That problem also involves tree-structures, and backtracking too.

For a problem that involves abstract tree structures and backtracking, you really ought to take a closer look at prolog.

(I don't get to say this often, prolog is useless at nearly everything else)

What you're trying to do sounds like an Expert System, and people have been writing them in prolog for years.

Constrained search is what prolog excels at, and what compilers optimize for. There is also a strongly typed variant if you want excellent performance.

If you've done a little programming before, "The Art of Prolog" is an excellent guide to the language.

tef
May 30, 2004

-> some l-system crap ->

kaschei posted:

Is there a good tool for replacing accented characters with their closest western equivalent?

In python here is a function unicodedata.normalize(form, unistr)

I can't recall the right argument off hand though.

tef
May 30, 2004

-> some l-system crap ->

L:ordSilent posted:

stupid question:

Is it possible to make a program to access a website and do whatever it is that you do on that website without the site having an api? (im not sure if thats the best way to ask this..)

I've done this for a living, it isn't fun.

One of the web unit testing frameworks will allow you to simulate user input, but it isn't good for heavy loads or fast requests.

tef
May 30, 2004

-> some l-system crap ->
If you can't decide which language to learn, flip a coin.

I would suggest using something not too astray from what you are used to (i.e a dynamicly typed functional language, before having fun with type inference).

SICP is a good text if you want to learn scheme, although large and dense. I am sure there are shorter texts. DrScheme is also a great IDE/Environment to learn in (so I am told).

Scheme is really geared towards learning to program and the documentation and tools available are mostly to that end.

Haskell, although useful is still the experimental stomping ground of new functional features. Monads can be understood, but that doesn't mean it will be straight forward using them well. (Haskell is also lazy).

ML or some of its dialects are eagerly evaluated, so it is a little more straight forward to reason about what the code is doing when, but it can make some things awkward.

If you're going to look at ml - ocaml or f# if you're on windows might be worth looking at too.

On the whole, I would say if you want to learn the most, read as much sicp as you can, and do exercises in scheme.

tef
May 30, 2004

-> some l-system crap ->
Who knows anything about constraint handling rules (CHR)?

I've been looking to do some type inference and program analysis and it looks to be a simple way to write one.

I've found some work on embedding CHR into HM, but I was wondering if anyone had any pointers?

tef
May 30, 2004

-> some l-system crap ->

rjmccall posted:

AFAIK Martin is the one really pushing type-analysis through CHRs, or at least he was before he became Gainfully Employed.

Thanks - it seems that constraint programming is mostly ignored for type systems, although they seem perfectly suited for them

quote:

The thing to remember about CHRs is that they're basically a full computation engine, so you quickly become bound by the restrictions of the solver you use.

I'm planning on implementing success typing using chr in swi/prolog. I don't think it's as limited as the chameleon prototype, or as academic.

But if you know any more I would be grateful.

tef
May 30, 2004

-> some l-system crap ->
the bash built in echo works, /bin/echo doesn't (on osx)


sh -c 'echo -e "\033]0;title prefix\007"'

tef fucked around with this message at 02:32 on Apr 28, 2009

tef
May 30, 2004

-> some l-system crap ->
I edited my post, but

code:
$ tcsh
% printf "\033]0;title prefixeee\007"
%


this also works.

tef
May 30, 2004

-> some l-system crap ->
I've been asked to set up a cruise control installation.

It's been fun so far.

Unfortunately I've now managed to get it so that after scheduling a build, it is successful but ignored.

[cc]Apr-30 12:25:36 jectController- build-cdm-trunk Controller: build result event: build successful

This appears in the cc logs, but the dashboard remains ignorant.

I'm struggling to find documentation on what feels like an awful, awful, awful product.

Any ideas, or good sources about kicking cruisecontrol until it bleeds?


Alternatively, if there are similar pieces of software for ci that suck a lot less I'd be interested too

tef
May 30, 2004

-> some l-system crap ->

This is a much better satire of paul graham:

http://www.paulgraham.com/hijack.html

tef
May 30, 2004

-> some l-system crap ->

L:ordSilent posted:

Ah. I guess that would be a browser. Scratch my pervious question then. What can i do to strip the html away from the information i want?

I found libxml2 to be quite good*, since I assume you're using c with libcurl.

* powerful, but I used the python wrapper lxml.

tef
May 30, 2004

-> some l-system crap ->
You can transform it into an iterative form with an explict stack:

code:
def quicksort(x):
   stack = [(0, len(x))]

   while stack:
       low, high = stack.pop() # take arguments from stack

       ....


       stack.push((nextl,nexth)) # push here is like the recursive call.
       stack.push((lowa, higha))

   return x

tef
May 30, 2004

-> some l-system crap ->
We can transform your first function into one that does not call itself:

It takes a low, high pair, and returns a list of new pairs that need to be sorted.

code:
def partial_quicksort(x,low,high):
	if low >= high:
		return [] # no new pairs to sort
	m = low
	for i in range (low+1, high+1):
		if x[i] < x[low]:
			m+=1
			t=i
			i=m
			m=t
	t=m
	m=low
	low=t[
	return [ (low,m-1), (m+1,high)]
If we call this function, it returns two pairs of values, that indicate the range that needs to be sorted next.

We could then do

code:
def quicksort(x,low,high): 
    ranges_to_sort = [ (low, high) ]
 
    while ranges_to_sort:  
       low_, high_ = ranges_to_sort.pop() # remove the last pair, and store it as low_, high_
       new_ranges = partial_quicksort(x, low_, high_)
       ranges_to_sort.extend(new_ranges) # add the new pairs


    return x

tef
May 30, 2004

-> some l-system crap ->
This also means you can test quicksort partial to see if it is partitioning the lists.

edit: because I haven't tested anything.

tef
May 30, 2004

-> some l-system crap ->
For too many reports.


And yes, hexadecimal (perma'd user enenthogen) got banned after posting in yospos.

tef
May 30, 2004

-> some l-system crap ->
SH/SC almost certianly.

tef
May 30, 2004

-> some l-system crap ->

Dijkstracula posted:

Oh really? I missed that memo.

http://forums.somethingawful.com/showthread.php?threadid=3057002&pagenumber=1#post355159936

Where is Unabomber, I always enjoyed his C arguments.

csammis posted:

If you're talking about teapot's permaban, it was in CoC


I must have been confusing it with one of his many bans in sh/sc.

tef
May 30, 2004

-> some l-system crap ->
Prolog solution :v:

code:
$ cat toot.pl
comb([],[]).
comb([L|T], [H|R]) :- member(H,L), comb(T,R).

$ swipl
?- [toot].
% toot compiled 0.00 sec, 900 bytes
true.

?- findall(X,comb([[2,3,4],[5,6],[0,1]],X),L).
L = [[2, 5, 0], [2, 5, 1], [2, 6, 0], [2, 6, 1], [3, 5, 0], [3, 5, 1], [3, 6|...], [3|...], [...|...]|...].

?- ^D
% halt
$ 

tef
May 30, 2004

-> some l-system crap ->
Actually I only saw the thread now.


Factor would be good too as it has reversible arithmetic.

tef
May 30, 2004

-> some l-system crap ->

Dijkstracula posted:

Wait, wait, what? What the hell are you talking about? Prolog is a logic language and has nothing to do with databases.

Datalog is an example to the contrary - logical programming makes it very easy to express the relationship between things.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Evil Home Stereo posted:

I need some ideas for a good way to go about solving this problem:

How do I code this efficiently without having to write out each possible calculation path?

Declaratively - you need to find a language in which you can express your constraints easily, and then use library code to solve it.

quote:

This is basically what I'm working with:
7 variables:
A,B,C,D,E,F,G
3 equations:
AB = CD + EF
A = C + E
G = C*V(D) + E*V(F) - A*V(B)
Where V(x) is a function

Given an 4 variables, find the rest.

You could do this in prolog but it would involve a lot of leg work, as although it is quite easy to write the solver, I'm not aware of any off the top of my head that will do enough for you.

Admittedly you could write a tiny constraint solver which would be fun.

Alternatively you could use a computer algebra system, which tend to cater to these sorts of programs.

Wikipedia is kinda useful here and it would be worth having a poke around:

http://en.wikipedia.org/wiki/Category:Computer_algebra_systems

http://en.wikipedia.org/wiki/SymPy

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply