Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. cs_new:Nn clist_count:NN
  2. {
  3. int_set:Nn l_tmpa_int {0}
  4. clist_set_eq:NN l_tmpa_clist #2
  5. bool_until_do:nn
  6. {
  7. clist_if_empty_p:N l_tmpa_clist
  8. }{
  9. clist_pop:NN l_tmpa_clist l_tmpa_tl
  10. int_add:Nn l_tmpa_int {1}
  11. }
  12. int_set_eq:NN #1 l_tmpa_int
  13. }
  14.  
  15. cs_new:Npn clist_length:N #1 {
  16. int_eval:n {
  17. 0 clist_map_function:NN #1 tl_elt_count_aux:n
  18. }
  19. }
  20.  
  21. cs_new:Nn clist_nth:Nn {
  22. int_compare:nTF { clist_length:N #1 < #2 }
  23. { ERROR }
  24. {
  25. exp_after:wN clist_nth_aux:nn exp_after:wN {#1} #2
  26. }
  27. }
  28. cs_new:Nn clist_nth_aux:nn {
  29. clist_nth_aux_i:nnnw {1}{#2} #1 , q_recursion_tail q_recursion_stop
  30. }
  31. cs_new:Npn clist_nth_aux_i:nnnw #1#2#3, {
  32. quark_if_recursion_tail_stop:n {#3}
  33. int_compare:nTF {#1==#2}
  34. {
  35. use_i_delimit_by_q_recursion_stop:nw {#3}
  36. }
  37. {
  38. clist_nth_aux_i:fnnw { int_eval:n {#1+1} } {#2}
  39. }
  40. }
  41. cs_generate_variant:Nn clist_nth_aux_i:nnnw {f}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement