torstenanders Posted April 13, 2017 Share Posted April 13, 2017 I would like to randomly pick a nested list. That works in principle, but the nesting is lost. (rnd-pick '(((h q) (h)) ((h. q) (h)) ((h. h) (h)))) => ((3/4 1/4) (1/2)) ; instead returns (3/4 1/4 1/2) I guess I have to roll my own :) (defun rnd-pick2 (selections &key (prob 0.5) seed) "Randomly selects a value from `selections' (without transforming that value). Very similar to rnd-pick, but leaves selected value unchanged (e.g., unflattened). Args prob: a floating-point number. Probability value. The default is 0.5. Example (rnd-pick2 '(((h q) (h)) ((h. q) (h)) ((h. h) (h)))) => ((h. q) (h)) " (rnd-seed seed) (nth (rnd1 :low 0 :high (1- (length selections)) :prob prob :seed (seed)) selections)) Best, Torsten AM 1 Quote Link to comment Share on other sites More sharing options...
Stephane Boussuge Posted April 14, 2017 Share Posted April 14, 2017 (rnd-pick '(((h q) (h)) ((h. q) (h)) ((h. h) (h))) :encode nil) => ((h. q) (h)) It works this way but i think it need to work also with :encode T. May be a bug in encoding process who remove nested list. Janusz ? S. Quote Link to comment Share on other sites More sharing options...
torstenanders Posted April 14, 2017 Author Share Posted April 14, 2017 Thanks. Unfortunately, that feature is not documented and therefore effectively does not exist for users. Janusz, I understand that writing documentation takes time that you do not have, but at least please make sure that the purpose of every function argument is briefly mentioned in the documentation. Otherwise, why would you program such features, if no-one can use them :) In order to help for this function, here is a suggestion. Quote With :encode T (the default) the function flattens out sublists and transforms OMN symbols (e.g., lengths symbols are turned into ratios), while :encode NIL returns selections unchanged. BTW: :encode T does indeed work that way for me (latest version, 1.2.21969M), contrary to what Stephane reports. Best, Torsten Quote Link to comment Share on other sites More sharing options...
opmo Posted April 14, 2017 Share Posted April 14, 2017 The argument encode is mentioned now in 23 functions (documents) - version 1.2.21977 Stephane Boussuge 1 Quote Link to comment Share on other sites More sharing options...
torstenanders Posted April 15, 2017 Author Share Posted April 15, 2017 Ah, brilliant. Sorry, I did not realise that this was an argument shared by many functions (like section, seed, or flat), which is therefore not documented. Just noticed the function encode-seq -- is that related to this argument? I understand that this function only removes repeat symbols, which I agree would be useful to do by default. However, encode-seq does not flatten the given lists, while rnd-pick does. That was my actual stumbling block here. (encode-seq '((h. q) (h))) => ((3/4 1/4) (1/2)) (rnd-pick '(((h q) (h)) ((h. q) (h)) ((h. h) (h)))) => (3/4 1/4 1/2) Does it really make sense to flatten the output of rnd-pick by default, or is that perhaps a mistake? Thanks again! Best, Torsten Quote Link to comment Share on other sites More sharing options...
opmo Posted April 16, 2017 Share Posted April 16, 2017 In OM we don't use double nested list. '(((h q) (h)) ((h. q) (h)) ((h. h) (h))) what is the purpose of this. Quote Link to comment Share on other sites More sharing options...
torstenanders Posted April 22, 2017 Author Share Posted April 22, 2017 Sorry, you seemingly just misread my question These double nested lists are single-nested alternatives for rnd-pick, but rnd-pick by default removes the nesting. (rnd-pick '(((h q) (h)) ((h. q) (h)) ((h. h) (h)))) => (3/4 1/4 1/2) Stephane pointed out that this can be avoided by setting the argument :encode to nil, but if others later run into this problem again this is still not explained in the documentation. I would argue that the default behaviour should be to preserve the (single) nesting, should it not? > In OM we don't use double nested list. > what is the purpose of this. This was not my question here, but I actually do use further nesting levels occasionally to represent additional information for intermediate processing, e.g., for representing sections Best, Torsten Quote Link to comment Share on other sites More sharing options...
opmo Posted April 22, 2017 Share Posted April 22, 2017 This is not a trivial thing to do because the function has to deal with so many cases. Please give me a REAL example of the use of double nested lists, especially with omn symbols. Quote Link to comment Share on other sites More sharing options...
torstenanders Posted April 22, 2017 Author Share Posted April 22, 2017 Sorry -- this is really about single-nested alternatives for rnd-pick, not a double nested lists. Torsten Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.