# Ppxlib usage help: record creation

**URL:** <https://discuss.ocaml.org/t/ppxlib-usage-help-record-creation/12774>\
**Category:** Learning\
**Tags:** ppxlib\
**Created:** [August 5, 2023, 8:03pm UTC](https://discuss.ocaml.org/t/ppxlib-usage-help-record-creation/12774 "2023-08-05T20:03:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluddy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bluddy/32/104_2.png) [@bluddy](https://discuss.ocaml.org/u/bluddy)\
**Post date:** [August 5, 2023, 8:03pm UTC](https://discuss.ocaml.org/t/ppxlib-usage-help-record-creation/12774/1 "2023-08-05T20:03:49Z")

</div>

The ppxlib tutorial is excellent, but the API documentation is unfortunately lacking.

I’m trying to create a pattern for getting the elements out of

```ocaml
let x = [%update {x with foo=bar; baz=fooz}] in 

```

To break down the record update, I use `Ast_pattern.pexp_record`. However, at this point I’m at a loss. The type of `pexp_record` is

`((Ppxlib.longident_loc * expression) list, 'a, 'b) t -> (expression option, 'b, 'c) t -> (expression, 'a, 'c) t`

Which combinators do I use to further take apart this expression?

---

<div class="post-metadata">

**Author:** ![Kakadu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kakadu/32/1204_2.png) [@Kakadu](https://discuss.ocaml.org/u/Kakadu)\
**Post date:** [August 6, 2023, 3:49pm UTC](https://discuss.ocaml.org/t/ppxlib-usage-help-record-creation/12774/2 "2023-08-06T15:49:33Z")

</div>

The API should be straitforward after some meditaion 🙂 Use many for lists, and double asterisk for pairs.

```ocaml
#use "topfind";;
#require "ppxlib";;
#require "ppxlib.metaquot";;

open Ppxlib.Ast_builder.Default
open Format

let loc = Location.none;;
let record = [%expr {x with foo=bar; baz=fooz}];;

let pp_expr ppf e =
  Format.fprintf ppf "%a" (Ocaml_common.Pprintast.expression) e

let () = Ppxlib.Ast_pattern.(
    let pfield = ( __**__ ) |> map2 ~f:(fun a b -> (a,b)) in
    parse (pexp_record (many pfield) __)
  )
  loc
  record
  (fun fields b ->
    List.iter (fun (fname,b) ->
      let _ : Ppxlib__.Import.longident_loc = fname in
      printf "? = %a\n" (pp_expr) b)fields;
    printf "%a\n%!" (pp_print_option pp_expr) b)

```

```auto
? = bar
? = fooz
x

```
