The Geeks Shall Inherit the Earth

Personal Ramblings of the Techhouse Admin

Skip to: Content | Sidebar | Footer

Code Syntax Highlight Test

7 April, 2010 (23:44) | Uncategorized | By: Brian

This is just a quick test of a code syntax highlight plug-in that I’m testing out. Here are some of the terribly-written beginner programs I wrote in erlang as answers to an old programming homework.

palinedromep([])  ->
palinedromep(List) when is_list(List), length(List) == 1 ->
palinedromep([First | Rest]) ->
 First == lists:last(Rest) andalso palinedromep(all_except_last(Rest)).

all_except_last ([_]) -> [];
all_except_last ([First|Rest]) ->
 [First | all_except_last(Rest)].

presentp(_, []) -> false;
presentp(Atom, [Head | Rest]) when is_atom(Atom), is_list(Head) ->
 presentp(Atom,Head) orelse presentp(Atom, Rest);
presentp(Atom, [Head | Rest]) when is_atom(Atom), is_tuple(Head) ->
 presentp(Atom,tuple_to_list(Head)) orelse presentp(Atom, Rest);
presentp(Atom, [Head | Rest]) when is_atom(Atom) ->
 Atom == Head orelse presentp(Atom, Rest).

duplicate_entries(Atom) when is_atom(Atom) -> false;
duplicate_entries([]) -> false;
duplicate_entries([_]) -> false;
duplicate_entries([Head | Rest] ) ->
 lists:member(Head, Rest) orelse duplicate_entries(Rest).

After looking back over them, I can think of much better ways of writing these samples using some of the built-in list libraries and/or tail recursion.

Write a comment

You need to login to post comments!