Nested Record Pattern Matching in R14A

Brian Williams mixolyde@REDACTED
Thu Jul 8 15:34:29 CEST 2010


I converted a small search algorithm project to use the new nested
record syntax in R14A.
My records are:
-record(state, {yard_state}).
-record(solution_state, {state = #state{}, moves, depth}).
-record(astar_solution_state, {solution_state = #solution_state{}, fvalue}).

I was able to use a line like this to access a field in the nested record:
Astar_Solution_State#astar_solution_state.solution_state#solution_state.state

Based on the example in the reference manual, I thought the pattern
for matching the state field would be:

function_call(#astar_solution_state.solution_state#solution_state{state
= State})

However, that gave me "illegal pattern" errors, and after a bit of
fiddling, I got this to work:
#astar_solution_state{solution_state = #solution_state{state = State}}

Is this intended? Or a bug?

-- 
Brian E. Williams
mixolyde@REDACTED
http://www.techhouse.us/wordpress-mu/brianw

"Never attribute to malice that which can be adequately
explained by stupidity." - Hanlon's Razor


More information about the erlang-questions mailing list